Perl编码-英国字符 [英] Perl Encode - UK characters

查看:95
本文介绍了Perl编码-英国字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自此问题的第2部分问题

This is a part 2 question from This Question.

所以我正在尝试:encode功能,但是一点运气都没有。

So I'm trying out the :encode functionality but having no luck at all.

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 €

结果是否应编码?我在这里做什么错了?

Shouldn't the results be encoded? what am I doing wrong here?

编辑:

添加了建议的内容:

use utf8;

现在我明白了:

Encoded UK: UK �

现在拔出头发:/

推荐答案

不要拉扯头发。您所做的一切正确,已完成,并且已经在获取预期的数据;输出使您感到困惑,因为您可能是从未针对Latin-9设置的终端查看的,而是针对其他编码(大概是UTF-8)的。

Don't pull your hair. You did everything right, are finished and are already getting the intended data; the output is confusing you because you probably look at it from a terminal that is not set up for Latin-9, but for a different encoding, presumably 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 .

代码点A4的确是拉丁文9中的欧元符号。

Codepoint A4 is indeed the Euro symbol in Latin-9.

这篇关于Perl编码-英国字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆