这是This Question的第2部分问题。
所以我尝试了:encode功能,但一点也没成功。
use Encode;
use utf8;
# Should print: iso-8859-15
print "Latin-9 Encoding: ".find_encoding("latin9")->name."\n";
my $encUK = encode("iso-8859-15", "UK €");
print "Encoded UK: ".$encUK."\n";结果:
Encoded UK: UK €结果不应该被编码吗?我在这里做错了什么?
编辑:
添加了建议:
use utf8;现在我得到了这个:
Encoded UK: UK �现在拔出头发:/
发布于 2010-06-16 03:54:49
别扯你的头发。您做的每件事都是正确的,都完成了,并且已经获得了预期的数据;输出让您感到困惑,因为您可能是从一个终端上查看它的,该终端不是为拉丁-9设置的,而是为不同的编码设置的,假设是UTF-8。
> perl -e'use utf8; use Encode; print encode "Latin-9", "Euro €"'
Euro �
> perl -e'use utf8; use Encode; print encode "Latin-9", "Euro €"' | hex
0000 45 75 72 6f 20 a4 Euro .Codepoint A4 is indeed the Euro symbol in Latin-9。
发布于 2010-06-18 00:44:44
从Perl5.8开始,“UTF;”只用于告诉utf8源文件是用UTF-8编码的。
那么源代码的编码是否真的与您告诉Perl的内容相匹配?
With 'vim‘必须使用此选项以UTF-8格式写入文件:
:set fenc=utf8要在加载文件时返回UTF-8,必须在.vimrc中定义文件编码:
set fileencodings=ucs-bom,utf-8,latin9https://stackoverflow.com/questions/3046595
复制相似问题