Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: How to avoid decoding string to utf-8.

by ikegami (Patriarch)
on Oct 11, 2020 at 20:51 UTC ( [id://11122712]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How to avoid decoding string to utf-8.
in thread How to avoid decoding string to utf-8.

First string gets double decoded

You are mistaken. utf8::decode won't do anything if the string is already decoded (except in the very specific and unusual cases I mentioned in my earlier post).

$ perl -CS -e' my $s = "\xC3\xA0\xC3\xA1\xC3\xA2\xC3\xA4"; printf("Before first decode: %1\$vX [%1\$s]\n", $s); utf8::decode($s) or warn("First decode failed.\n"); printf("After first decode: %1\$vX [%1\$s]\n", $s); utf8::decode($s) or warn("Second decode failed.\n"); printf("After second decode: %1\$vX [%1\$s]\n", $s); ' Before first decode: C3.A0.C3.A1.C3.A2.C3.A4 [àáâä] After first decode: E0.E1.E2.E4 [àáâä] Second decode failed. After second decode: E0.E1.E2.E4 [àáâä]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found