2011-02-10 80 views
16

为什么我会在“autodie”之后得到不同的输出?autodie-pragma对编码有影响吗?

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

回答

17

除非有人有更好的理由来的,这看起来像相对于open编译与autodie的错误。

将上次打开更改为open my $fh2, '<:utf8', 'test.txt';可以修复我系统上的问题。所以这可能是一个临时工作。

我只是检查RT,这是注册的错误:

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

看起来有使用过载open功能不同的方式每个编译做。

+1

我刚刚为这个bug修补了一个补丁。 https://github.com/pfenwick/autodie/pull/12 – Schwern 2012-06-19 21:53:17

相关问题