Does the autodie-pragma have influence on the encoding?

烂漫一生 提交于 2020-01-19 09:42:32

问题


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

回答1:


Unless someone comes in with a better reason, this looks like a bug with autodie in relation to the open 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.



来源:https://stackoverflow.com/questions/4959384/does-the-autodie-pragma-have-influence-on-the-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!