用perl从文件中读取西里尔字符

用perl从文件中读取西里尔字符,perl,file,encoding,Perl,File,Encoding,我在用perl从文件中读取西里尔字符时遇到问题 文本文件以记事本形式编写,包含“ббжзззззззбззззбзззб。 这是我的密码: #!/usr/bin/perl use warnings; use strict; open FILE, "text.txt" or die $!; while (<FILE>) { print $_; } 如果我使用UTF-8编码保存它,并使用包编码中的函数decode('UTF-8',$\),我会得到: Wide cha

我在用perl从文件中读取西里尔字符时遇到问题

文本文件以记事本形式编写,包含“ббжзззззззбззззбзззб。 这是我的密码:

#!/usr/bin/perl

use warnings;
use strict;

open FILE, "text.txt" or die $!;

while (<FILE>) {
    print $_;   
}
如果我使用UTF-8编码保存它,并使用包编码中的函数decode('UTF-8',$\),我会得到:

Wide character in print at test.pl line 11, <TEXT> line 1.
test.pl第11行第1行打印的宽字符。 还有一堆不可读的字符


我在windows 7x64中使用命令提示符,您正在解码输入,但“忘记”对输出进行编码

您的文件可能是使用

您的终端需要

使用

使用open':std',':encoding(cp866)';
使用open IO=>':编码(cp1251)';

打开(我的$FILE,'文件使用的编码是什么?终端使用的编码是什么?我正在使用windows 7中的命令提示符键入
chcp
,并将
cp
前置到获得的数字,以获得第二个问题的答案。(例如,我的
cp437
)我的第一个问题呢?第一个问题:我尝试了两种编码,8位ansi和utf-8。第二个问题cp866“ansi”不是编码。可能是cp1251。
Wide character in print at test.pl line 11, <TEXT> line 1.
use open ':std', ':encoding(cp866)';
use open IO => ':encoding(cp1251)';
open(my $FILE, '<', 'text.txt')
   or die $!;
use open ':std', ':encoding(cp866)';
open(my $FILE, '<:encoding(cp1251)', 'text.txt')
   or die $!;