Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Data::XDumper by xmath
in thread Data::XDumper by xmath

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (5)
    As of 2020-06-07 08:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?



      Results (42 votes). Check out past polls.

      Notices?