gpt4 book ai didi

perl - 如何使用 utf8 编码和 open pragma

转载 作者:行者123 更新时间:2023-12-02 07:03:33 24 4
gpt4 key购买 nike

当使用 pragma use open qw(:std :utf8);

时,我遇到了 utf8::encode 问题

示例

#!/usr/bin/env perl

use v5.16;
use utf8;
use open qw(:std :utf8);

use Data::Dumper;

my $word = "+банк";
say Dumper($word);
say utf8::is_utf8($word) ? 1 : 0;

utf8::encode($word);
say Dumper($word);
say utf8::is_utf8($word) ? 1 : 0;

输出

$VAR1 = "+\x{431}\x{430}\x{43d}\x{43a}";
1
$VAR1 = '+банк';
0

当我删除此 pragma use open qw(:std :utf8); 时,一切正常。

$VAR1 = "+\x{431}\x{430}\x{43d}\x{43a}";
1
$VAR1 = '+банк';
0

先谢谢你!

最佳答案

如果您要将 utf8::encode($word); 替换为 use open qw(:std :utf8);,您实际上需要删除 utf8::encode($word);。在不起作用的版本中,您编码了两次。

关于perl - 如何使用 utf8 编码和 open pragma,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16484066/

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