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


In reply to Encode: unable to change encoding of strings by Hue-Bond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.