gpt4 book ai didi

Perl:latin1 模块中的字符串文字 - 我想要 utf8

转载 作者:行者123 更新时间:2023-12-05 00:37:34 27 4
gpt4 key购买 nike

Date::Holidays::DK模块中,某些丹麦节日的名称是用 Latin1 编码编写的。例如,1 月 1 日是“Nytårsdag”。我该怎么办$x下面为了得到一个正确的 utf8 编码的字符串?

use Date::Holidays::DK;
my $x = is_dk_holiday(2011,1,1);

我尝试了 use utf8 的各种组合和 no utf8之前/之后 use Date::Holidays::DK ,但似乎没有任何效果。我也尝试使用 Encode 的 decode ,没有运气。进一步来说,
use Date::Holidays::DK;
use Encode;
use Devel::Peek;
my $x = decode("iso-8859-1",
is_dk_holiday(2011,1,1)
);
Dump($x);
print "January 1st is '$x'\n";

给出输出
SV = PV(0x15eabe8) at 0x1492a10
REFCNT = 1
FLAGS = (PADMY,POK,pPOK,UTF8)
PV = 0x1593710 "Nyt\303\245rsdag"\0 [UTF8 "Nyt\x{e5}rsdag"]
CUR = 10
LEN = 16
January 1st is 'Nyt sdag'

(在 t 和 s 之间有一个无效字符)。

最佳答案

use utf8 and no utf8 before/after use Date::Holidays::DK, but it does not seem to have any effect.



正确的。 utf8 pragma 仅表示程序的源代码是用 UTF-8 编写的。

I also tried to use Encode's decode, with no luck.



你没有正确地理解这一点,你实际上做了正确的事。您现在拥有一串 Perl 字符并且可以对其进行操作。

with an invalid character between t and s



这个你也解释错了,其实是 å特点。

您想输出 UTF-8,因此缺少编码步骤。
my $octets = encode 'UTF-8', $x;
print $octets;

请阅读 http://p3rl.org/UNI用于介绍编码主题。您始终必须显式或隐式地解码和编码。

关于Perl:latin1 模块中的字符串文字 - 我想要 utf8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6694560/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com