【问题标题】:Does the autodie-pragma have influence on the encoding?autodie-pragma 对编码有影响吗?
【发布时间】:2011-02-10 15:54:41
【问题描述】:

为什么我在“autodie”之后得到不同的输出?

#!/usr/bin/env perl
use warnings;
use 5.012;
use utf8;
use open ':encoding(utf-8)';
use open ':std';

open my $fh, '>', 'test.txt' or die $!;
say $fh 'käse';
close $fh;

open my $fh1, '<', 'test.txt' or die $!;
while ( my $row = readline( $fh1 ) ) {
    print $row;
}
close $fh1;

use autodie;

open my $fh2, '<', 'test.txt';
while ( my $row = readline( $fh2 ) ) {
    print $row;
}
close $fh2;

# Output:
# käse
# käse

【问题讨论】:

    标签: perl encoding autodie


    【解决方案1】:

    除非有人有更好的理由,否则这看起来像是 autodieopen 杂注相关的错误。

    将最后一次打开更改为open my $fh2, '&lt;:utf8', 'test.txt'; 解决了我系统上的问题。所以这可能是一个临时的解决方法。

    我刚刚检查了 RT,这是一个已注册的错误:

    https://rt.cpan.org/Public/Bug/Display.html?id=54777

    看起来它与使用不同方式重载 open 函数的每个编译指示有关。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 2014-03-30
    • 2016-01-13
    • 2020-11-12
    • 2011-08-06
    • 2011-11-12
    • 2014-01-05
    相关资源
    最近更新 更多