in reply to JSON, Data::Dumper and accented chars in utf-8
how do I make the records output through Data::Dumper come out as "Particípio Passado" instead of "Partic\x{c3}\x{ad}pio Passado"?
The string isn't "Particípio Passado"; it's the UTF-8 encoding of "Particípio Passado". If you had "Particípio Passado", Data::Dumper would print one of the following (depending on a couple of factors):
$VAR1 = "Particípio Passado"; $VAR1 = "Partic\x{ed}pio Passado"; $VAR1 = "Partic\355pio Passado";
(The first would only show up correctly if you properly encode your output. We'll get back to that.)
If you're using JSON::XS, this problem would arise if you didn't call ->utf8.
my $json_parser = JSON::XS->new->utf8; my $data = $json_parser->decode($json_string);
If I do a normal print of the keys, they come right
Given that the string is wrong, that indicates there are other problems. (i.e. Two wrongs made a right.)
First, I bet your Perl source file is encoded using UTF-8, but you didn't tell Perl that using
use utf8;
Secondly, I bet you have a UTF-8 terminal, but you didn't tell Perl that using one of
use open ':std', 'locale'; use open ':std', ':encoding(UTF-8)';
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: JSON, Data::Dumper and accented chars in utf-8
by Ralesk (Pilgrim) on Jan 21, 2012 at 22:08 UTC | |
by ikegami (Patriarch) on Jan 22, 2012 at 06:21 UTC | |
by Ralesk (Pilgrim) on Jan 21, 2012 at 22:11 UTC | |
by silentius (Monk) on Jan 21, 2012 at 22:42 UTC | |
by Ralesk (Pilgrim) on Jan 21, 2012 at 23:04 UTC | |
by ikegami (Patriarch) on Jan 22, 2012 at 06:24 UTC | |
by Ralesk (Pilgrim) on Jan 22, 2012 at 16:23 UTC |