Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: XML::Parser Encoding (UTF-8 -> ISO-8859-1)

by bart (Canon)
on Sep 12, 2002 at 20:15 UTC ( #197337=note: print w/replies, xml ) Need Help??

in reply to XML::Parser Encoding (UTF-8 -> ISO-8859-1)

Annoying, isn't it? Perl has its own idea of whether your data should be treated as UTF8 or as 8-bit encoding, and it may not agree with your idea. If you concat a plain 8-bit string with a string marked as UTF-8, Perl will convert the 8-bit string to UTF-8 as well, whether you want it or not.

The trickery is all connected to the UTF8 flag, which is a bit flag attached to each string. For the data that XML::Parser returns, that UTF8 flag is set.

To get rid of this behaviour, clear the UTF8 flag. One way you can do it, is like this:

sub de_utf8 { use bytes; return "$_[0]"; }
This way, the resulting string will be the same byte data as the original string, but with the UTF8 flag cleared. So now, the string should stay in ISO-Latin-1.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2023-03-28 18:24 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (68 votes). Check out past polls.