相关疑难解决方法(0)

如何使用Perl打开Unicode文件?

我正在使用osql对数据库运行几个sql脚本,然后我需要查看结果文件以检查是否发生了任何错误.问题是Perl似乎不喜欢结果文件是Unicode的事实.

我写了一个小测试脚本来测试它,输出结果都出现了问题:

$file = shift;

open OUTPUT, $file or die "Can't open $file: $!\n";
while (<OUTPUT>) {
    print $_;
    if (/Invalid|invalid|Cannot|cannot/) {
        push(@invalids, $file);
        print "invalid file - $inputfile - schedule for retry\n";
        last;
    }            
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我尝试使用解码,decode_utf8但它没有任何区别.我还尝试在打开文件时设置编码.

我认为问题可能是osql将结果文件放在UTF-16格式中,但我不确定.当我在textpad中打开文件时,它只是告诉我'Unicode'.

编辑:使用perl v5.8.8编辑:十六进制转储:

file name: Admin_CI.User.sql.results
mime type: 

0000-0010:  ff fe 31 00-3e 00 20 00-32 00 3e 00-20 00 4d 00  ..1.>... 2.>...M.
0000-0020:  73 00 67 00-20 00 31 00-35 00 30 00-30 00 37 00  s.g...1. …
Run Code Online (Sandbox Code Playgroud)

unicode perl encoding file

10
推荐指数
3
解决办法
7771
查看次数

标签 统计

encoding ×1

file ×1

perl ×1

unicode ×1