加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – autodie-pragma对编码有影响吗?

发布时间:2020-12-15 21:18:06 所属栏目:大数据 来源:网络整理
导读:为什么我会得到“autodie”不同的输出? #!/usr/bin/env perluse 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 (
为什么我会得到“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

解决方法

除非有更好的理由进入,否则这看起来像一个与开放伪指令有关的bug。

改变最后一次打开我的$ fh2,’<:utf8','test.txt';解决我的系统上的问题。所以这可能是临时工作。 我只是检查了RT,这是一个注册的错误: https://rt.cpan.org/Public/Bug/Display.html?id=54777

看起来它与每个pragma都使用不同的方法来重载open函数。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读