编码:使用 'utf8'

4

当我已经使用了use encoding 'utf8'时,是否可以省略use '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} );
}

2
请参见Q:https://dev59.com/questions/R0bRa4cB1Zd3GeqPz2Mz - rubber boots
2个回答

5

use encoding的使用已被官方弃用。该模块已被废弃,因为它会导致非常奇怪的行为。相反,您应该使用以下内容:

use utf8;                             # Source code is UTF-8
use open ':std', ':encoding(UTF-8)';  # STDIN,STDOUT,STDERR are UTF-8.

0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接