【发布时间】:2015-01-22 08:16:51
【问题描述】:
我在这里最终想要实现的是将文件中的所有小写字符转换为大写并将它们写入终端。
use utf8;
binmode STDOUT, ":utf8";
$text = "ABCÅÄÖ\n";
$text =~ tr/A-Ö/a-ö/;
print $text;
输出:
abcåäö
正如预期的那样。
但是当我尝试从文件中导入相同的文本时,它会变得很疯狂。
use utf8;
binmode STDOUT, ":utf8";
open FILE, $filename or die "An error occurred while reading the file: $!";
$text = join '', <FILE>;
close FILE or die "An error occurred while closing the file: $!";
$text =~ tr/A-Ö/a-ö/;
print $text;
输出
ABCÃÃÃ
我假设导入的文本没有正确编码。有人知道如何在导入文本时对其进行编码吗?
提前致谢。
杰克
【问题讨论】: