string - Perl 程序从十六进制值打印 Unicode
问题描述
我从 Perl 开始,对如何在给定十六进制字符串变量的情况下呈现 unicode 字符感到困惑。
#!/usr/bin/perl
use warnings;
foreach my $i (0..10000) {
my $hex = sprintf("%X", $i);
print("unicode of $i is \x{$hex}\n");
}
print("\x{2620}\n");
print("\x{BEEF}\n");
给我警告:Illegal hexadecimal digit '$' ignored at perl.pl line 9.
并且没有打印价值\x{$hex}
解决方案
两者都chr($num)
生成pack('W', $num)
一个由具有指定值的单个字符组成的字符串,就像这样"\x{XXXX}"
做一样。
因此,您可以使用
print("unicode of $i is ".chr(hex($hex))."\n");
要不就
print("unicode of $i is ".chr($i)."\n");
请注意,您的程序没有任何意义
use open ':std', ':encoding(UTF-8)';
推荐阅读
- apache-kafka - 为什么骆驼卡夫卡生产者很慢?
- java - 你如何制作一个没有 UI 的应用程序,所以当你打开它时,它会运行一些代码
- json - Gson - 带有值的 Kotlin 枚举的良好序列化
- r - 如何计算有多少条道路与多边形相交?
- php - HTTP 到 HTTPS 重定向在 IIS 中不起作用
- angular - 使用 Angular 7 上传文件时,表单数据并不总是在 Chrome 中发送
- angular - 两个组件数据绑定有问题
- spring-boot - Spotify dockerfile 无法推送图像,资源已定义
- asp.net-core-2.0 - 在 IIS 中并排运行多个 ASP.NET Core 2.2 webapps
- python - 如何从这个结果中选择 %f ?