in reply to Re^4: In need of a Dumper that has no pretentions to being anything else.
in thread In need of a Dumper that has no pretentions to being anything else.
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: In need of a Dumper that has no pretentions to being anything else.
by fergal (Chaplain) on Feb 23, 2005 at 20:59 UTC | |
by demerphq (Chancellor) on Feb 23, 2005 at 23:27 UTC | |
by fergal (Chaplain) on Feb 24, 2005 at 01:50 UTC | |
by BrowserUk (Patriarch) on Feb 24, 2005 at 04:26 UTC | |
by demerphq (Chancellor) on Feb 24, 2005 at 07:54 UTC |