Hue-Bond has asked for the wisdom of the Perl Monks concerning the following question:
PerlMonks seems to send pages in ISO-8859-1 encoding, which is giving me some unexpected trouble. To fix it, I've decided to use Encode to translate data to UTF-8 as soon as I download it. However, Perl is laughing at my attempts (the string is "Ámbito" in ISO-8859-1 and UTF-8 encodings):
$ perl -MEncode -e '$_="\xc3\x81mbito"; print $_, encode "iso-8859-1", + $_' | xxd 0000000: c381 6d62 6974 6fc3 816d 6269 746f ..mbito..mbito $ perl -MEncode -e '$_="\xc3\x81mbito"; print $_, decode "iso-8859-1", + $_' | xxd 0000000: c381 6d62 6974 6fc3 816d 6269 746f ..mbito..mbito $ perl -MEncode -e '$_="\xc1mbito"; print $_, encode "iso-8859-1", + $_' | xxd 0000000: c16d 6269 746f c16d 6269 746f .mbito.mbito $ perl -MEncode -e '$_="\xc1mbito"; print $_, decode "iso-8859-1", + $_' | xxd 0000000: c16d 6269 746f c16d 6269 746f .mbito.mbito
Most probably, PEBKAC but I don't see the "P". It isn't late enough (2:00 am) for this to be a silly thing :). I've "resolved" it using from_to but I don't have the feeling that this is the right way.
Update: No echo | perl needed. Changed examples accordingly. Clarified the meaning of the string literal. Updated PEBKAC link to use [jargon://].
--
David Serrano
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Encode: unable to change encoding of strings
by shmem (Chancellor) on Jul 09, 2006 at 08:06 UTC | |
by Hue-Bond (Priest) on Jul 09, 2006 at 08:44 UTC | |
Re: Encode: unable to change encoding of strings
by ioannis (Abbot) on Jul 09, 2006 at 02:20 UTC | |
by Hue-Bond (Priest) on Jul 09, 2006 at 02:45 UTC | |
Re: Encode: unable to change encoding of strings
by graff (Chancellor) on Jul 09, 2006 at 22:43 UTC |