autodie-pragma 对编码有影响吗? [英] Does the autodie-pragma have influence on the encoding?

查看:25
本文介绍了autodie-pragma 对编码有影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why do I get after the "autodie" a different output?

#!/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

推荐答案

除非有人提出更好的理由,否则这看起来像是与 open 相关的 autodie 的错误代码> 编译指示.

Unless someone comes in with a better reason, this looks like a bug with autodie in relation to the open pragma.

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

Changing the last open to open my $fh2, '<:utf8', 'test.txt'; fixes the problem on my system. So that could be a temporary work around.

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

I just checked RT, and this is a registered bug:

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

看起来它与使用不同方式重载 open 函数的每个 pragma 相关.

Looks like it has to do with each pragma using different ways of overloading the open function.

这篇关于autodie-pragma 对编码有影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆