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

In reply to Bug in Perl 5.6.1 ? by gregorovius

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.