http://qs321.pair.com?node_id=197337


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.