I thought that too when I first came across it. Here's the way I remember it now: Perl has its own internal way of storing the data - don't worry about what it is, just know that it's some special thing. When your code acquires data (from STDIN or another filehandle or a database or a web request) the data has some encoding. To process it you need to decode it from that encoding into the special internal format, so you use decode. Conversely when sending data out of perl (to STDOUT or a database or a web response or ...) you need to encode it back into what the receiving system expects so you use encode. This is why it helps to think of utf-8, utf-16, Latin-1, etc. as encodings (and this is indeed what they are).

All the magic shortcuts you might come across such as encoding layers are performing these operations automatically for you but really it's just decode and encode under the bonnet.


In reply to Re^3: Match full utf-8 characters by hippo
in thread Match full utf-8 characters by Allasso

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.