Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Potential bug in chr

by ikegami (Patriarch)
on Feb 05, 2018 at 01:31 UTC ( [id://1208452]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Potential bug in chr
in thread Potential bug in chr

use open ':std', ':encoding(UTF-8)';
makes far more sense than
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1208452]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found