makes far more sense thanuse open ':std', ':encoding(UTF-8)';
binmode STDOUT, ':utf8';
It binmodes STDIN, STDOUT and STDERR (with the safer :encoding(UTF-8)). It also sets the default encoding for the instances of open in the scope (making the :encoding('UTF-8') redundant in the open).
This shows that if you happen to join a byte-oriented string with a unicode string in perl, the result will be a unicode string.
Which is irrelevant to the question at hand.
The first print worked because the string contained non-bytes (chars outside of 0..255), which can't be printed without encoding. perl guessed that you meant to encode them using UTF-8 (and warns you about this ("Wide character in...")).
perl had no way of knowing the second print was wrong because it only contained bytes (chars in 0..255), so it printed the string unaltered.
In reply to Re^3: Potential bug in chr
by ikegami
in thread Potential bug in chr
by perlboy_emeritus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |