Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://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":



  • 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.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found