Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Data::Dumper and UTF-8

Reply
Thread Tools

Data::Dumper and UTF-8

 
 
August Karlstrom
Guest
Posts: n/a
 
      10-21-2007
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:umper;
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
 
Reply With Quote
 
 
 
 
Brian Wakem
Guest
Posts: n/a
 
      10-21-2007
August Karlstrom wrote:

> 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:umper;
> 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-D....121/Dumper.pm

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


--
Brian Wakem
 
Reply With Quote
 
 
 
 
augukarl@yahoo.se
Guest
Posts: n/a
 
      10-22-2007
On 21 Okt, 23:32, Brian Wakem <(E-Mail Removed)> wrote:
> What version of Perl?


v5.8.8

> Fromhttp://search.cpan.org/~ilyam/Data-Dumper-2.121/Dumper.pm
>
> "Pure Perl version of Data:umper escapes UTF-8 strings correctly only in
> Perl 5.8.0 and later."


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


August

 
Reply With Quote
 
Peter Makholm
Guest
Posts: n/a
 
      10-22-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

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

>
> 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
 
Reply With Quote
 
jl_post@hotmail.com
Guest
Posts: n/a
 
      10-22-2007
On Oct 21, 3:27 pm, August Karlstrom <(E-Mail Removed)> wrote:
>
> I'm trying to make Dumper display an UTF-8 string but I can't get it to
> work:
>

 
Reply With Quote
 
jl_post@hotmail.com
Guest
Posts: n/a
 
      10-22-2007
On Oct 22, 12:34 pm, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
>
> 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), );
>
> Either way should work.)



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

$Data:umper::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

 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      10-27-2007
On 2007-10-21 21:27, August Karlstrom <(E-Mail Removed)> wrote:
> 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:umper;
> 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


--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | (E-Mail Removed) |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments