Data::Dumper and UTF-8

A

August Karlstrom

Hi,

I'm trying to make Dumper display an UTF-8 string but I can't get it to
work:

$ cat test.pl
#!/usr/bin/perl -w

use strict;
use Data::Dumper;
use utf8;

binmode(STDOUT, ":utf8");

my $s = "\x{263a}";

print "$s\n";
print Dumper($s);
print Dumper("☺");

$ ./test.pl
☺
$VAR1 = "\x{263a}";
$VAR1 = "\x{263a}";

Any clues?


Regards,

August
 
B

Brian Wakem

August said:
Hi,

I'm trying to make Dumper display an UTF-8 string but I can't get it to
work:

$ cat test.pl
#!/usr/bin/perl -w

use strict;
use Data::Dumper;
use utf8;

binmode(STDOUT, ":utf8");

my $s = "\x{263a}";

print "$s\n";
print Dumper($s);
print Dumper("?");

$ ./test.pl
?
$VAR1 = "\x{263a}";
$VAR1 = "\x{263a}";

Any clues?


What version of Perl?

From http://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm

"Pure Perl version of Data::Dumper escapes UTF-8 strings correctly only in
Perl 5.8.0 and later."
 
A

augukarl

What version of Perl?
v5.8.8

Fromhttp://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm

"Pure Perl version of Data::Dumper escapes UTF-8 strings correctly only in
Perl 5.8.0 and later."

Yes, I've read that. What does Pure Perl mean?


August
 
P

Peter Makholm

Yes, I've read that. What does Pure Perl mean?

It means implementet only using Perl and not by implementing parts of
it in C (or any other language).

//Makholm
 
J

jl_post

print eval("my " . Dumper($s)); # prints ☺

(The "my " part is to suppress a warning given because the output's
"$VAR1" is caught by "use warnings;" and "use strict;". Optionally,
you may remove that part by using the following lines instead:

# Remove the "$VAR1 = " part with substr():
print eval( substr(Dumper($s), 8) );

Either way should work.)


Jason, I just now figured out (by reading "perldoc Data::Dumper")
that the "$VAR = " part can be suppressed by setting
$Data::Dumper::Terse to 1. Therefore, you could add the following two
lines to the end of your script:

$Data::Dumper::Terse = 1; # to suppress "$VAR1 = "
print eval Dumper($s); # prints ☺

and you'll see that, although Dumper may not output text in the form
you want, eval()ling the output text does return it in the form you
want.

-- Jean-Luc
 
P

Peter J. Holzer

Hi,

I'm trying to make Dumper display an UTF-8 string but I can't get it to
work:

$ cat test.pl
#!/usr/bin/perl -w

use strict;
use Data::Dumper;
use utf8;

binmode(STDOUT, ":utf8");

my $s = "\x{263a}";

print "$s\n";
print Dumper($s);
print Dumper("☺");

$ ./test.pl
☺
$VAR1 = "\x{263a}";
$VAR1 = "\x{263a}";

Looks ok to me. What output did you expect?

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top