in reply to Re^2: A Character Set Enquiry
in thread A Character Set Enquiry

Is there a difference between decoding and encoding?

It's all so confusing... wouldnt decoding just be the same thing as encoding to the original? iow: encoding latin1 to utf8 is the same thing as decoding utf8 (to latin1)? whats the difference?

im trying to do some hex examples for myself but im having some trouble... sigh... I've decided I hate character sets

Replies are listed 'Best First'.
Re^4: A Character Set Enquiry
by massa (Hermit) on Jul 11, 2008 at 16:07 UTC
    • encoding means taking a Perl string and transforming it in a binary buffer that represents the same string, in some codepage.
    • decoding is the opposite: taking a binary buffer that you know is encoded in some codepage and transforming it in a Perl string
    Perl strings are arrays of codepoints (Unicode characters) that can represented internally either as a Latin1-encoded buffer or as a (relaxed) UTF-8 encoded buffer. So, in your examples, there is no "encoding from XXX to XXX" (unless you use Encode::from_to, that is a decode followed by an encode). You can get a string that you know it's in the UTF-8 codepage, decode it (save it in Perl internal format) and then encode that internal string, for instance to the Latin1 codepage.
    []s, HTH, Massa