Depends on what you mean by "right".
Something that is reasonably close to valid perl that will recreate the original data. In this case the code is just plain wrong, with or without Purity mode.
this information should be preserved otherwise certain structures would have identical output even though they're not identical.
You mean like Data::Dumper does below? (And Data::Dump::Streamer does not?)
#!perl -l
use Data::Dumper;
use Data::Dump::Streamer;
my ($x,$y);
$x=\$y;
$y=\$x;
my $ary=[];
$ary->[0]=\$ary->[1];
$ary->[1]=\$ary->[0];
print "No purity\n---";
print Dumper([$x,$y]);
print Dumper($ary);
{
print "With purity\n---";
local $Data::Dumper::Purity=1;
print Dumper([$x,$y]);
print Dumper($ary);
}
print "============\nWith DDS:";
print Dump([$x,$y]);
print Dump($ary);
print "************\nFergals Example With Dumper:";
{
my %s=('key',1);
my $s=\$s{'key'};
print Dumper(\%s,$s);
print Dumper($s,\%s);
print "============\nWith DDS:";
print Dump(\%s,$s);
print Dump($s,\%s);
}
__END__
No purity
---
$VAR1 = [
\\$VAR1->[0],
${$VAR1->[0]}
];
$VAR1 = [
\\$VAR1->[0],
${$VAR1->[0]}
];
With purity
---
$VAR1 = [
\\do{my $o},
do{my $o}
];
${${$VAR1->[0]}} = $VAR1->[0];
$VAR1->[1] = ${$VAR1->[0]};
$VAR1 = [
\\do{my $o},
do{my $o}
];
${${$VAR1->[0]}} = $VAR1->[0];
$VAR1->[1] = ${$VAR1->[0]};
============
With DDS:
$ARRAY1 = [
\do { my $v = 'V: $ARRAY1->[1]' },
\do { my $v = 'V: $ARRAY1->[0]' }
];
${$ARRAY1->[0]} = $ARRAY1->[1];
${$ARRAY1->[1]} = $ARRAY1->[0];
$ARRAY1 = [
'R: $ARRAY1->[1]',
'R: $ARRAY1->[0]'
];
$ARRAY1->[0] = \$ARRAY1->[1];
$ARRAY1->[1] = \$ARRAY1->[0];
************
Fergals Example With Dumper:
$VAR1 = {
'key' => 1
};
$VAR2 = \$VAR1->{'key'};
$VAR1 = \1;
$VAR2 = {
'key' => ${$VAR1}
};
============
With DDS:
$HASH1 = { key => 1 };
$SCALAR1 = \$HASH1->{key};
$SCALAR1 = 'R: $HASH1->{key}';
$HASH1 = { key => 1 };
$SCALAR1 = \$HASH1->{key};
probably possible to write something that would reconstruct the correct sturucture but it would involve some sort of constraint solver
See Data::Dump::Streamer for a dumper that handles these things properly. DD does a single pass over its dataset, and a depth first one at that, this almost guarantees that it will get things like this wrong. These are very old bugs, first raised by merlyn years ago (see a bug report that involves the dog pound) that still havent been fixed, and frankly probably will never be fixed.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.