This is a very strange bug. It appears to be happening because the replacement is coming from an array; witness the following code:

#/usr/bin/perl -w require 5.8.0; use strict; my($a1, $d1) = ("\x{00E0}", "\x{00E4}"); my($a2, $d2) = ("\x{0430}", "\x{0434}"); my($a3, $d3) = (["\x{0430}"], ["\x{0434}"]); my @a4 = "\x{0430}"; my @d4 = "\x{0434}"; for (\&t2, \&t3, \&t4, \&t5) { my $text = $d1.$a1; warn "Before = ", join('.', unpack ("U*", ${text})), "\n\n"; &$_($text); warn "After = ", join('.', unpack ("U*", ${text})), "\n\n"; } sub t2 { $_[0] =~ s/$d1/$d2/g; $_[0] =~ s/$a1/$a2/g; } sub t3 { $_[0] =~ s/$d1/$d3->[0]/g; $_[0] =~ s/$a1/$a3->[0]/g; } sub t4 { $_[0] =~ s/$d1/$d4[0]/g; $_[0] =~ s/$a1/$a4[0]/g; } sub t5 { my $a5 = $a4[0]; my $d5 = $d4[0]; $_[0] =~ s/$d1/$d5/g; $_[0] =~ s/$a1/$a5/g; }

The t3() and t4() calls fail for me under perl-5.8.0 and with recent development sources at patchlevel 18736. The very latest development sources (@18777) succeed for all four cases, so this has clearly been fixed by a very recent patch.

The success of t5() in the above code suggests a workaround - grab the replacement variable into a scalar variable, and use that scalar for the replacement.

Hugo

In reply to Re: utf8 encoding bug? by hv
in thread utf8 encoding bug? by zemplen

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.