【发布时间】:2016-05-01 09:09:38
【问题描述】:
所以我有 utf8 文本文件,我想读入,将行放入数组中,然后打印出来。但是输出没有正确打印符号,例如输出行如下所示:
“arnÅ¿tein gehört gräflichen”
所以我尝试通过一行测试脚本,直接粘贴到 perl 脚本中,而不是从文件中读取它。那里的输出非常好。我检查了文件,它们是 utf8 unicode。文件仍然必须导致输出问题(?)。
因为脚本太长,我只是把它剪成相关的: (进入目录,打开文件,将输入引导到函数&align,分析它,将其添加到数组中,打印数组)
#!/usr/bin/perl -w
use strict;
use utf8;
binmode(STDIN,":utf8");
binmode(STDOUT,":utf8");
binmode(STDERR,":utf8");
#opens directory
#opens file from directory
if (-d "$dir/$first"){
opendir (UDIR, "$dir/$first") or die "could not open: $!";
foreach my $t (readdir(UDIR)){
next if $first eq ".";
next if $first eq "..";
open(GT,"$dir/$first/$t") or die "Could not open GT, $!";
my $gt= <GT>;
chomp $gt;
#directly pasted lines in perl - creates correct output
&align("det man die Profeſſores der Philoſophie re- ");
#lines from file - output not correct
#&align($gt);
close GT;
next;
}closedir UDIR;
}
有什么想法吗?
【问题讨论】:
标签: perl unicode utf-8 character-encoding file-handling