in reply to malformed UTF-8 character in JSON string in perl
If I do not use Data::Dumper, I obtain this:$ perl -E ' use utf8; use Data::Dumper; my $data = qq( { "cat" : "text abcd" } ); print Dumper($data); ' $VAR1 = " { \"cat\" : \"text \x{2013} abcd\" } ";
i.e. a warning but the right output. As previously mentioned by Corion, it is a feature of Data::Dumper to display the UTF-8 escape sequences.$ perl -E 'use utf8; my $data = qq( { "cat" : "text abcd" } ); say $data ' Wide character in say at -e line 4. { "cat" : "text abcd" }
Using binmode, as I already told you several days ago in an answer to your previous post with the same content, I no longer have any warning:
Have you tried binmode?$ perl -E 'use utf8; my $data = qq( { "cat" : "text abcd" } ); binmode STDOUT, ":utf8"; say $data; ' { "cat" : "text abcd" }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: malformed UTF-8 character in JSON string in perl
by Yllar (Novice) on Aug 11, 2015 at 13:55 UTC | |
by Laurent_R (Canon) on Aug 11, 2015 at 15:47 UTC | |
by Yllar (Novice) on Aug 11, 2015 at 16:00 UTC | |
by aitap (Curate) on Aug 12, 2015 at 08:12 UTC |