Perl's use encoding pragma breaking UTF strings
- by Karel Bílek
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?