Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'

by Juerd (Abbot)
on Feb 25, 2008 at 15:04 UTC ( [id://670014]=note: print w/replies, xml ) Need Help??


in reply to Re^2: i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'
in thread i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'

If you have the raw bytestring, the easiest way to see if it's valid UTF-8 is to decode it to a unicode string. If that fails, it wasn't utf8 enough :)

utf8::decode($string) or die "Input is not valid UTF-8";
or
utf8::decode(my $text = $binary) or die "Input is not valid UTF-8";
If you leave out the "or die" clause, any invalid UTF-8 will just be seen as ISO-8859-1.

Update: changed the examples as per ikegami's sound response.

Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }

Replies are listed 'Best First'.
Re^4: i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'
by ikegami (Patriarch) on Feb 25, 2008 at 17:40 UTC
    That should be
    utf8::decode(my $text = $binary) or die "Input is not valid UTF-8";

    It works in-place.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found