That wouldn't be more useful, since that's not what it does.

Perl decodes from UTF-8 with, and it decodes from ASCII (with 8-bit clean literals) without. And it does that for the entire source code, not just literals. And the literals don't necessarily use the upgraded format, even with use utf-8.

Your explanation is simply completely wrong.


In the end, it's about whether the strings you are working with are using byte semantics or character semantics.

No. It very much isn't. It affects the encoding used to decode the entire code, not the internal storage format of literals.

$ perl -Mv5.14 -e'use utf8; sub fée { }' $ perl -Mv5.14 -e'no utf8; sub fée { }' Illegal declaration of subroutine main::f at -e line 1.

Because binmode ":encoding()" only works with strings with character semantics and does nothing with byte semantics.

That's not true either. It works for both.

$ perl -Mv5.14 -e' binmode STDOUT, ":encoding(UTF-8)"; $_ = "\xE9"; utf8::upgrade($_); say; ' | od -t x1 0000000 c3 a9 0a 0000003 $ perl -Mv5.14 -e' binmode STDOUT, ":encoding(UTF-8)"; $_ = "\xE9"; utf8::downgrade($_); say; ' | od -t x1 0000000 c3 a9 0a 0000003

"Byte semantics" and "Unicode semantics" are (confusing and misleading) terms used to describe code suffering from The Unicode Bug. :encoding does not suffer from The Unicode Bug.

:encoding is not even being discussed!


In reply to Re^3: binmode(':encoding(UTF-8)') did not produce utf8 for me by ikegami
in thread binmode(':encoding(UTF-8)') did not produce utf8 for me by hexcoder

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.