编码:使用'utf8'

问题描述 投票:4回答:2

已经使用use 'utf8'时可以省略use encoding 'utf8'编译指示吗?

#!/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} );
}
perl utf-8 character-encoding encode
2个回答
2
投票

是,但是请确保您熟悉Perldoc中的CAVEATS


2
投票

我建议您停止使用encoding,而不是utf8。前者导致非常奇怪的行为。

use utf8;                  # Source code is UTF-8
use open ':std', ':utf8';  # STDIN,STOUT,STERR is UTF-8.
© www.soinside.com 2019 - 2024. All rights reserved.