Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: By the shine on my bald pate, I dislike this encoding stuff

by Anonymous Monk
on Mar 06, 2018 at 11:09 UTC ( #1210397=note: print w/replies, xml ) Need Help??


in reply to By the shine on my bald pate, I dislike this encoding stuff

open (ORDERFILE, '<:encoding(UTF-8)', $emailfile) or return (@err, "Co +uld not open order email file: $emailfile"); #... my $filedata = <ORDERFILE>; #... eval { my $utf8 = decode("utf8", $filedata, Encode::FB_CROAK ) };

First you're applying an IOLayer to a filehandle to obtain characters decoded from UTF-8, then you additionally decode unicode characters as if they were UTF-8 bytes. If this is working, it's by chance (i.e. when reading ASCII-only files).

You should either open with :encoding(UTF-8) (but then you'll get warnings on non-UTF-8 text) or open without the IOLayer and do the decoding manually with FB_CROAK option.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1210397]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2018-06-18 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (111 votes). Check out past polls.

    Notices?