当我已经在使用use 'utf8'时,我可以省略use encoding '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} );
}发布于 2011-03-10 04:23:59
官方不鼓励使用use encoding 。该模块已被弃用,因为它会导致非常奇怪的行为。相反,您应该使用以下内容:
use utf8; # Source code is UTF-8
use open ':std', ':encoding(UTF-8)'; # STDIN,STDOUT,STDERR are UTF-8.发布于 2011-03-09 19:29:02
可以,但请确保您熟悉perldoc中的CAVEATS。
https://stackoverflow.com/questions/5244719
复制相似问题