Message updated. Please kindly skip to the solution part if you have already read the posted question. Thanks!
Here is the code below to show my problem:
The input data file for the test was saved using the Notepad built-in notepad in the form of UTF-8 encoding. It has the following three lines:
abacus æbәkәs
abalone æbәlәuni
abandon әbændәn
The Perl script file was also saved using the built-in Notepad window as UTF-8 encoding. It contains the following code:
use Data::Dumper;
use strict;
use autodie;
open my $in,'<',"./hash_test.txt";
open my $out,'>',"./hash_result.txt";
my %hash = map {split/\t/,$_,2} <$in>;
print $out Dumper(\%hash),"\n";
print $out "$hash{abacus}";
print $out "$hash{abalone}";
print $out "$hash{abandon}";
On the output, the hash table looks fine:
$ VAR1 = {
'abalone' => 'æbәlәuni
',
'abandon' => 'әbændәn',
'Abacus' =>' æbәkәs
''
};
, :
æbәlәuni
әbændәn
Perl :
Use of uninitialized value $hash{"abacus"} in string at C:\test2.pl line 11, <$i
n> line 3.
? - ? .
, :) , , , :)
@Sinan, 100% , , , , , UTF-8 - Perl . , "<: utf8" " > : utf8" , , utf-8 . .
, , Perl :
use Data::Dumper;
use strict;
use autodie;
open my $in,'<',"./hash_test.txt";
open my $out,'>',"./hash_result.txt";
seek $in,3,0;
my %hash = map {split/\t/,$_,2} <$in>;
print $out Dumper(\%hash);
print $out $hash{abacus};
print $out $hash{abalone};
print $out $hash{abandon};
- , :
$VAR1 = {
'abalone' => 'æbәlәuni
',
'abandon' => 'әbændәn',
'abacus' => 'æbәkәs
'
};
æbәkәs
æbәlәuni
әbændәn
, script UTF-8, utf-8, UTF-8.
, . , @, . , , .
, :
open my $in,'<:utf8',"./hash_test.txt";
open my $out,'>:utf8',"./hash_result.txt";
my %hash = map {split/\t/,$_,2} <$in>;
print $out Dumper(\%hash);
print $out $hash{abacus};
print $out $hash{abalone};
print $out $hash{abandon};
:
$VAR1 = {
'abalone' => "\x{e6}b\x{4d9}l\x{4d9}uni
",
'abandon' => "\x{4d9}b\x{e6}nd\x{4d9}n",
"\x{feff}abacus" => "\x{e6}b\x{4d9}k\x{4d9}s
"
};
æbәlәuni
әbændәn
:
Use of uninitialized value in print at C:\hash_test.pl line 13, line 3.