Perl's use encoding pragma breaking UTF strings
Posted
by
Karel Bílek
on Stack Overflow
See other posts from Stack Overflow
or by Karel Bílek
Published on 2011-03-19T15:43:55Z
Indexed on
2011/03/19
16:10 UTC
Read the original article
Hit count: 291
perl
I have a problem with Perl and Encoding pragma.
(I use utf-8 everywhere, in input, output, the perl scripts themselves. I don't want to use other encoding, never ever.)
However. When I write
binmode(STDOUT, ':utf8');
use utf8;
$r = "\x{ed}";
print $r;
I see the string "í" (which is what I want - and what is 00+ED unicode char). But when I add the "use encoding" pragma like this
binmode(STDOUT, ':utf8');
use utf8;
use encoding 'utf8';
$r = "\x{ed}";
print $r;
all I see is a box character. Why?
Moreover, when I add Data::Dumper and let the Dumper print the new string like this
binmode(STDOUT, ':utf8');
use utf8;
use encoding 'utf8';
$r = "\x{ed}";
use Data::Dumper;
print Dumper($r);
I see that perl changed the string to "\x{fffd}"
. Why?
© Stack Overflow or respective owner