in reply to Re^2: binmode(':encoding(UTF-8)') did not produce utf8 for me
in thread binmode(':encoding(UTF-8)') did not produce utf8 for me

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!