Perl处理中文时出现乱码
目前在用Perl(Linux环境下)做一个工具,目的是错误信息的多语言支持。即根据Error ID找到对应语言的字符串,用其替换文本文件中的英文字符串。目前西方语言支持没有问题,唯独中文和日文写入文本后是乱码。也上网搜索了相关解决方案,但没有解决问题。我的简要实现代码如下:
my $oCode = "UTF-8";
my $oFmtJ = Spreadsheet::ParseExcel::FmtUnicode->new(Unicode_Map => $oCode);
my $excel = Spreadsheet::ParseExcel::Workbook->Parse("$error_xls",$oFmtJ);
foreach my $sheet (@{$excel->{Worksheet}}) {
#printf("Sheet: %s\n", $sheet->{Name});
$sheet->{MaxRow} ||= $sheet->{MinRow};
foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
$sheet->{MaxCol} ||= $sheet->{MinCol};
my @array=();
foreach my $col ($sheet->{MinCol} .. $sheet->{MaxCol}) {
my $cell = $sheet->{Cells}[$row][$col];
if ($cell) {
push @array, $cell->{Val};
}
}
此时,$cell->{Val}如果读取的是中文,则为乱码。
请教各位大侠其中的原因?不胜感激。