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

Re: Difficulty with UTF-8 and file contents

by choroba (Cardinal)
on Apr 13, 2020 at 13:14 UTC ( [id://11115454]=note: print w/replies, xml ) Need Help??


in reply to Difficulty with UTF-8 and file contents

There's no need to reopen the DATA handle, you can specify its encoding via binmode:
binmode *DATA, ':encoding(UTF-8)'; while (<DATA>) { # This populates $_ with decoded Unicode data, not b +ytes. ... )
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Difficulty with UTF-8 and file contents
by ikegami (Patriarch) on Apr 14, 2020 at 01:53 UTC

    That's useless. DATA, being the handle used by perl to read the source, is affected by the existing use utf8;.

    use if $ARGV[0], "utf8"; printf "%vX\n", scalar(<DATA>); __DATA__ é
    $ perl a.pl 0 C3.A9.A $ perl a.pl 1 E9.A

    The OP's problem appears to be a lack of encoding of the output, not a lack of decoding of the input.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-24 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found