in reply to Re: Encode: unable to change encoding of strings
in thread Encode: unable to change encoding of strings
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
|
|---|