Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: How to know to know if string is utf8 encoded or decoded.

by haj (Chaplain)
on Jul 26, 2019 at 17:55 UTC ( #11103472=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to know to know if string is utf8 encoded or decoded.
in thread How to know to know if string is utf8 encoded or decoded.

Wrapping the code in eval only makes sense if you ask decode to die if it can't decode:
eval { $unicode = Encode::decode($from,$str,Encode::FB_CROAK); }; if ($@) { &ConvertEncodingError("($from -> utf8)\n$@"); return $str; }
You should be aware that in case of a decoding error, $str will be overwritten.

Replies are listed 'Best First'.
Re^4: How to know to know if string is utf8 encoded or decoded.
by ikegami (Pope) on Jul 29, 2019 at 05:54 UTC

    The third arg needs to be Encode::FB::CROAK | Encode::LEAVE_SRC since you don't want $from to change.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2020-04-10 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (49 votes). Check out past polls.

    Notices?