Perl Encode.pm cannot decode string with wide character

前端 未结 3 651
走了就别回头了
走了就别回头了 2021-02-07 08:14

I was running a perl app which uses /opt/local/lib/perl5/5.12.4/darwin-thread-multi-2level/Encode.pm

and issues an error

Cannot deco

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-07 08:17

    encode takes a string of Unicode code points and serialises them into a string of bytes.

    decode takes a string of bytes and deserialises them into Unicode code points.

    That message means you passed a string containing one or more characters above 255 (non-bytes) to decode, which is obviously an incorrect argument.

    >perl -MEncode -E"for (254..257) { say; decode('iso-8859-1', chr($_)); }"
    254
    255
    256
    Wide character in subroutine entry at .../Encode.pm line 176.
    

    You ask for a workaround, but the bug is yours. Perhaps you are accidentally trying to decode something you already decoded?

提交回复
热议问题