Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
转换十六进制字符串UTF-16 Perl内部表示_Perl_Unicode_Utf 16 - Fatal编程技术网

转换十六进制字符串UTF-16 Perl内部表示

转换十六进制字符串UTF-16 Perl内部表示,perl,unicode,utf-16,Perl,Unicode,Utf 16,我不知道为什么这个代码不起作用: use strict; use warnings; use Encode qw/decode/; my $entity_unicode = "00A0"; $entity_unicode = decode("UTF-16", pack('H4', $entity_unicode)); print $entity_unicode, "\n"; 它打印出:“UTF-16:unrecogned BOM a0 at/usr/lib/perl/5.10/Encode.p

我不知道为什么这个代码不起作用:

use strict;
use warnings;
use Encode qw/decode/;
my $entity_unicode = "00A0";
$entity_unicode = decode("UTF-16", pack('H4', $entity_unicode));
print $entity_unicode, "\n";
它打印出:“UTF-16:unrecogned BOM a0 at/usr/lib/perl/5.10/Encode.pm第174行。”。

如果要解码的字符串开头没有BOM(U+FEFF),就无法知道00A0是U+00A0(UTF-16be)还是U+0A00(UTF-16le,由Windows使用)。当没有BOM时,必须指定确切的编码。在这种情况下,这是UTF-16be