http://qs1969.pair.com?node_id=235744


in reply to •Re: Data::XDumper
in thread Data::XDumper

I'm not trying to reinvent YAML in any way. I'm not interesting in serializing data structure, nor reading them in in different languages.

I want an accurate dump of perl data structures. Neither Dumper nor Denter offer this, and I doubt YAML does either (although I haven't checked really - feel free to correct me)

an example which shows where Dumper and Denter go wrong:
http://tnx.nl/scribble/420FRAP
how would YAML handle that?

•Update: the above link died.. so here it is, expanded to include other dumping formats mentioned also:

my $x = 4; my $xx = sub{\@_}->(\$x, \$x); my $y = \4; my $yy = sub{\@_}->($y, $y); bless \$xx->[0], 'Foo'; bless \$xx->[1], 'Bar'; bless \$yy->[0], 'Foo'; bless \$yy->[1], 'Bar'; use Data::XDumper qw(Dump); print "******** Data::XDumper ********\n"; Dump $xx, $yy; print "\n"; use Data::Dumper; print "******** Data::Dumper ********\n"; print Dumper $xx, $yy; print "\n"; use Data::Denter; print "******** Data::Denter ********\n"; print Denter $xx, $yy; print "\n"; # (by merlyn's suggestion in the reply) $Data::Dumper::Purity = 1; print "******** Data::Dumper with purity ********\n"; print Dumper $xx, $yy; print "\n"; # and also use YAML (); print "******** YAML ********\n"; print YAML::Dump $xx, $yy; print "\n";

And the corresponding output:
******** Data::XDumper ******** [ Foo \ $L002: 4, Bar \$L002 ] [ $L001: Bar \<ro> 4, $L001 ] ******** Data::Dumper ******** $VAR1 = [ \4, $VAR1->[0] ]; $VAR2 = [ \4, $VAR2->[0] ]; ******** Data::Denter ******** @ $(REF00001) 4 $(*REF00001-1) @ $(REF00002) 4 $(*REF00002-1) ******** Data::Dumper with purity ******** $VAR1 = [ \4, do{my $o} ]; $VAR1->[1] = $VAR1->[0]; $VAR2 = [ \4, do{my $o} ]; $VAR2->[1] = $VAR2->[0]; ******** YAML ******** --- #YAML:1.0 - &1 !perl/ref: =: 4 - *1 --- #YAML:1.0 - &1 !perl/ref: =: 4 - *1