autodie-pragma 对编码有影响吗?
为什么我在“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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非有人有更好的理由,否则这看起来像是与
open
pragma 相关的autodie
的错误。将上次打开更改为
open my $fh2, '<:utf8', 'test.txt';
修复了我的系统上的问题。所以这可能是一个临时的解决办法。我刚刚检查了 RT,这是一个已注册的错误:
https://rt .cpan.org/Public/Bug/Display.html?id=54777
看起来它与使用不同方式重载
open
函数的每个编译指示有关。Unless someone comes in with a better reason, this looks like a bug with
autodie
in relation to theopen
pragma.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.I just checked RT, and this is a registered bug:
https://rt.cpan.org/Public/Bug/Display.html?id=54777
Looks like it has to do with each pragma using different ways of overloading the
open
function.