- 论坛徽章:
- 0
|
我现在遇到这个问题 比较棘手
请看 (test.txt是一个包含中文的文本)
test1.pl
#!/usr/bin/perl
open (FILET,"/home/test.txt");
@lines=<FILET>;
close(FILET);
for ($i=0; $i < @lines ;$i++) {
print $lines[$i];
print "\n";
}
$str = "你好";
print $str;
直接运行perl test1.pl > test1res.txt
然后打开 http://test1res.txt
则 test.txt中的中文显示正常 但是"你好"处显示乱码
test2.pl
#!/usr/bin/perl
use encoding 'gb2312' , STDIN => 'gb2312', STDOUT => 'gb2312';
open (FILET,"/home/test.txt");
@lines=<FILET>;
close(FILET);
for ($i=0; $i < @lines ;$i++) {
print $lines[$i];
print "\n";
}
$str = "你好";
print $str;
直接运行perl test2.pl > test2res.txt
然后打开 http://test2res.txt
则 test.txt中的中文显示成为类似"x\{2e45} x\{3e0651f}" 的样子 但是"你好"处显示正常
test3.pl
#!/usr/bin/perl
open (FILET,"/home/test.txt");
@lines=<FILET>;
close(FILET);
for ($i=0; $i < @lines ;$i++) {
print $lines[$i];
print "\n";
}
$str = "你好";
$str = decode('gb2312',$str);
print $str;
直接运行perl test3.pl > test3res.txt
然后打开 http://test3res.txt
则 换成网页uft8格式时 "你好"处显示正常 test.txt中文还是不正常
我不知是系统问题 还是perl的问题 总之很奇怪 |
|