Perl与mojibake生成错误消息

时间:2016-06-28 17:49:48

标签: perl

我正在学习Perl,在系统控制台中我执行的脚本显示以下奇怪的字符:

open(my $fh, '<', 'teste') or warn $!
Arquivo ou diretório não encontrado at reply input line 1.

消息应为:Arquivo ou diretório não encontrado at reply input line 1.

我认为它是iso-8859-1

我想拥有UTF-8编码/解释的所有东西,所以我学会了将以下几行放在源代码中:

use open qw/:std :utf8/; # entrada e saída em utf8                                                                                         
use utf8; # código fonte em utf8

在我的系统上:

LANG=pt_BR.UTF-8
LANGUAGE=pt_BR:pt:en
LC_CTYPE=pt_BR.UTF-8
LC_NUMERIC="pt_BR.UTF-8"
LC_TIME="pt_BR.UTF-8"
LC_COLLATE="pt_BR.UTF-8"
LC_MONETARY="pt_BR.UTF-8"
LC_MESSAGES="pt_BR.UTF-8"
LC_PAPER="pt_BR.UTF-8"
LC_NAME="pt_BR.UTF-8"
LC_ADDRESS="pt_BR.UTF-8"
LC_TELEPHONE="pt_BR.UTF-8"
LC_MEASUREMENT="pt_BR.UTF-8"
LC_IDENTIFICATION="pt_BR.UTF-8"
LC_ALL=

我的终端由putty处理。

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

这不是Perl,它是终端设置。

正如@MattJacob指出的那样终端可以。

我刚刚做了一个测试转储注册表:

regedit /ea "D:\putty.reg.old" HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions

翻译中的putty GUI&gt;远程字符集默认显示为UTF-8编码。但它没有设置。所以我只需将其更改为任何编码,保存会话并将其再次保存到putty.reg中以进行文件比较。

fc putty.reg.old putty.reg
***** putty.reg.old
"Wordness224"="2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2"
"LineCodePage"=""
"CJKAmbigWide"=dword:00000000
***** PUTTY.REG
"Wordness224"="2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2"
"LineCodePage"="ISO-8859-1:1998 (Latin-1, West Europe)"
"CJKAmbigWide"=dword:00000000
*****

现在我们看到“LineCodePage”=“”为空。现在选择UTF-8应该可以工作!

fc putty.reg.old putty.reg
***** putty.reg.old
"Wordness224"="2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2"
"LineCodePage"=""
"CJKAmbigWide"=dword:00000000
***** PUTTY.REG
"Wordness224"="2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2"
"LineCodePage"="UTF-8"
"CJKAmbigWide"=dword:00000000
*****

让我们进入服务器并进行测试!

~(master ✗) perl -e 'open(my $fh, "<", "teste") or warn $!'
Arquivo ou diretório não encontrado at -e line 1.