and you get character semantics (not byte semantics) when doing stuff with that string
There's no such thing. If an operation behaves differently depending on the internal encoding of the string, it's a bug. These are being fixed. e.g. pack was fixed in 5.10.0. Regex matches and other are being fixed for 5.12. Text::CSV_XS was fixed in 0.46.
that's the point of using "decode()" and the encoding IO layer
Not at all. The point of decode is to decode characters. It has nothing to do with the internal storage of strings.
You can have decoded characters with the utf8 flag off.
You can encoded characters with the utf8 flag on.
If you need to play with the internal encoding, utf8::upgrade and utf8::downgrade are the appropriate tools.
This is what the previously linked document shows.
the "perl-internal utf8" storage of characters in the rang 0x80-0xFF is single-byte.
Impossible. The high bit indicates the presence of a multiple byte char.
$ perl -MEncode -le'print length encode "utf8", decode "UTF-16le", "\x
+FE\x00"'
2
or
$ perl -MDevel::Peek -MEncode -le'Dump decode "UTF-16le", "\xFE\x00"'
...
PV = 0x8172e78 "\303\276"\0 [UTF8 "\x{fe}"]
CUR = 2
...
U+000000-U+00007F: One byte
U+000080-U+0007FF: Two bytes
U+000800-U+00FFFF: Three bytes
U+010000-U+10FFFF: Four bytes
|