如何在开放式编译指示中使用utf8编码 [英] How to use utf8 encode with open pragma

查看:214
本文介绍了如何在开放式编译指示中使用utf8编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用编译指示use open qw(:std :utf8);

示例

#!/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

当我删除此编译指示use open qw(:std :utf8);时,一切正常.

When I remove this pragma use open qw(:std :utf8);, everything is OK.

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

谢谢你!

推荐答案

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

If you're going to replace utf8::encode($word); with use open qw(:std :utf8);, you'll actually need to remove the utf8::encode($word);. In the version that doesn't work, you're encoding twice.

这篇关于如何在开放式编译指示中使用utf8编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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