Perl 编码:使用';utf8';
当我已经在使用Perl 编码:使用';utf8';,perl,utf-8,character-encoding,encode,Perl,Utf 8,Character Encoding,Encode,当我已经在使用使用编码“utf8”时,是否可以省略使用“utf8”-pragma #!/usr/bin/env perl use warnings; use 5.012; use Encode qw(is_utf8); use encoding 'utf8'; my %hash = ( '☺' => "☺", '\x{263a}' => "\x{263a}", 'ä' => "ä", 'a' => "a" ); for my $key ( sort keys %ha
使用编码“utf8”时,是否可以省略使用“utf8”
-pragma
#!/usr/bin/env perl
use warnings;
use 5.012;
use Encode qw(is_utf8);
use encoding 'utf8';
my %hash = ( '☺' => "☺", '\x{263a}' => "\x{263a}", 'ä' => "ä", 'a' => "a" );
for my $key ( sort keys %hash ) {
say "UTF8 flag is turned on in the STRING $key" if is_utf8( $hash{$key} );
say "UTF8 flag is NOT turned on in the STRING $key" if not is_utf8( $hash{$key} );
}
是的,但请确保您熟悉perldoc中的。官方不鼓励使用编码。该模块不受欢迎,因为它会导致非常奇怪的行为。相反,您应该使用以下选项:
use utf8; # Source code is UTF-8
use open ':std', ':encoding(UTF-8)'; # STDIN,STDOUT,STDERR are UTF-8.
见Q: