in reply to Re: "use encoding" behaviour change under Perl 5.10?
in thread "use encoding" behaviour change under Perl 5.10?

Thanks for your example. I understand that "use encoding" applies to the program source (string literals etc.) but that it affects the chr function was quite a surprise to me.

As for replacing it with something more manageable, I certainly will, but I needed a workaround right now and could not afford to dig into the code at the moment.

  • Comment on Re^2: "use encoding" behaviour change under Perl 5.10?

Replies are listed 'Best First'.
Re^3: "use encoding" behaviour change under Perl 5.10?
by jdd (Acolyte) on Mar 21, 2009 at 19:32 UTC
    From perldoc perlunicode:

    The "chr()" and "ord()" functions work on characters, similar to "pack("W")" and "unpack("W")", not "pack("C")" and "unpack("C")". "pack("C")" and "unpack("C")" are methods for emulating byte-oriented "chr()" and "ord()" on Unicode strings. While these methods reveal the internal encoding of Unicode strings, that is not something one normally needs to care about at all.

    Being a no-expert at all in that, just hope the following can help to give you or others a good direction:

    perl -Mencoding=utf8 -le 'print unpack "C", chr 156'
    156
    
    perl -Mencoding=utf8 -M'Encode qw(from_to)' -le '$c = chr 156; from_to($c, "iso-8859-3", "utf-8"); print ord $c'
    156