develooper Front page | perl.perl5.porters | Postings from April 2008

Re: [perl #43617] [RESOLVED] Data::Dumper ignores ^M in scalars?

Thread Previous
From:
Bram
Date:
April 28, 2008 01:04
Subject:
Re: [perl #43617] [RESOLVED] Data::Dumper ignores ^M in scalars?
Message ID:
op.uaa9zrvj5efjgi@darwin.mechelen.pearldoc.com
On Mon, 28 Apr 2008 00:18:28 +0200, Daniel Hagerty <hag@linnaean.org>  
wrote:

>     Apologies on not having responded earlier, I probably missed the
> response.

Thank you for replying.

>     FWIW, useqq now produces expected results; usage without useqq
> continues to produce an empty string.

#!/usr/bin/perl

use Data::Dumper;
print Dumper("a\rb");


Does it produce an empty string or do you see - in the shell - something  
like:  b';R1 = 'a'
Or using | od -tx1: 0000000 24 56 41 52 31 20 3d 20 27 61 0d 62 27 3b 0a
(a = 61, \r = 0d, b = 62)


> Tried this with perl 5.8.8 w/
> Data::Dumper 2.121_08 on both netbsd 4.0 and debian 4.0 systems.
>
>     If one is to believe that Data::Dumper's intent is to produce a
> string that can be eval'd to produce a copy of the original object
> like it's manual page indicates, this appears to be a bug.

Actually, it can be eval'ed without a problem.
You can even write it in a file, read that file and eval it.

What you can not do is copy the output from the shell/console, paste it in  
another file and eval that.
The handling of  ^M (or \r) is seen by the shell (or atleast I think) as a  
way how to control the display of the output.
The same is true for ANSI escapes. (if your  
shel/terminal/console/display/... supports them)

This is because the shell/console reads them and changes the text that is  
displayed.
If you do not want the shell to do that then you can set  $Useqq = 1   
which prevents them from being outputted.

In all, I do not think this is a bug.


Try for example:

#!/usr/bin/perl

use Data::Dumper;
my $foo = Dumper("a\rb");
print "Foo = $foo";
eval $foo;

$Data::Dumper::Useqq = 1;
print "eval \$foo = " . Dumper($VAR1);
$VAR1 = "";

my $fn = "/tmp/foo_$$_" . time;
open my $fh, ">", $fn or die "Can't open file $fn: $!";
print $fh $foo;
close $fh;

require $fn;
unlink $fn;
print "require $fn = " . Dumper($VAR1);
$VAR1 = "";

__END__

I hope you now agree with me that it is not a bug.

Kind regards,

Bram

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About