How can I decode UTF-16 data in Perl when I don't know the byte order?

后端 未结 3 1813
心在旅途
心在旅途 2020-12-30 13:12

If I open a file ( and specify an encoding directly ) :

open(my $file,\"<:encoding(UTF-16)\",\"some.file\") || die \"error $!\\n\";
while(<$file>) {         


        
3条回答
  •  被撕碎了的回忆
    2020-12-30 14:13

    You need to specify either UTF-16BE or UTF-16LE. See http://perldoc.perl.org/Encode/Unicode.html#Size%2c-Endianness%2c-and-BOM

提交回复
热议问题