from_to does decode and encode inplace

Yes, that's what the documentation says. I'm using it accordingly, so no surprises here.

perl -MEncode -e '$_="\xc1mbito"; print $_; $_ = decode "iso-8859-1", $_; print encode "utf-8", $_'

So you are using decode to translate the input from ISO-8859-1 to "Perl's internal form", whatever it is, and then encode to print it out in the desired encoding. That's two calls, and I thing this "problem" could be solved with just one, after all it's a simple matter of changing the encoding of a string! The gotcha may be in that I'm cheating by assuming that "Perl's internal form" is UTF-8 (I think it is but I shouldn't be assuming it anyway). So what I was trying was to decode the ISO-8859-1 input into UTF-8 with a call to decode and then use it without further modification (this is the third example in the OP; the others are just for illustrating the issue).

Your snippet makes sense and agrees with what I've read recently somewhere, that says that data should be decoded when acquired, then used within the program and finally encoded again when giving it back to the outside world.

--
David Serrano


In reply to Re^2: Encode: unable to change encoding of strings by Hue-Bond
in thread 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.