The following code, when ran under Perl 5.6.0 and earlier,
will correctly print the latin1 variable in the second
print statement. Under Perl 5.6.1 this variable
misteriously reverts to UTF8 and its german characters are
printed as the two characters in the UTF8 encoding, and
look like gibberish.
The first print statement shows that
interpolating utf8 together with latin1 variables works
under perl 5.6.1, so the utf8 variable gotten from
XML::RSS must be special in a bad way that makes
perl 5.6.1 confused. XML::RSS uses XML::Parser to parse XML
so the problem could also be in XML::Parser.
Note that if I converted the $utf8_from_xml_rss variable
to latin1 the print statement would work fine.
This almost
caused me a headache last week when a client in a different
continent and behind a firewall was reporting that a
program my company supplied was printing gibberish, and we
couldn't reproduce it.
The output produced by the program follows right after it.
#!/usr/bin/perl -w
use strict;
use Unicode::String;
use XML::RSS;
my $latin1 = "Größter Anstieg seit März 1998";
my $utf8 = Unicode::String::latin1( $latin1 )->utf8;
print "1: $utf8 - $latin1 \n";
my $rss_content = <<'EOF';
<?xml version="1.0" encoding="ISO-8859-1" ?><rss version="0.91"><chann
+el><item> <title>Größter Anstieg seit März 1998</title></item></ch
+annel></rss>
EOF
my $rss = new XML::RSS;
$rss->parse( $rss_content );
foreach my $item ( @{ $rss->{items} } ) {
# XML::RSS always returns its findings in UTF8
my $utf8_from_xml_rss = $item->{title};
print "2: $utf8_from_xml_rss - $latin1 \n";
}
# under Perl 5.6.0 and earlier the output is:
# 1: GröÃter Anstieg seit März 1998 - Größter Anstieg seit März 1998
+
# 2: GröÃter Anstieg seit März 1998 - Größter Anstieg seit März 1998
+
# under Perl 5.6.1 the output is
# 1: GröÃter Anstieg seit März 1998 - Größter Anstieg seit März 1998
+
# 2: GröÃter Anstieg seit März 1998 - GröÃter Anstieg seit März 19
+98