Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Pretty Dump Cross References

by wollmers (Scribe)
on Nov 28, 2014 at 23:31 UTC ( [id://1108674]=perlquestion: print w/replies, xml ) Need Help??

wollmers has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

One of my subs returns structures like this:

$VAR1 = [ [ [ 0, 0 ], [ 2, 2 ] ], [ [ 1, 0 ], $VAR1->[0][1] ] ];

The above is the output of Data::Dumper, which in case of larger structures is hard to compare for debugging. Is there something better or maybe an option to get a dump without reference notation like this:

$VAR1 = [ [ [ 0, 0 ], [ 2, 2 ] ], [ [ 1, 0 ], [ 2, 2 ] ] ];

Replies are listed 'Best First'.
Re: Pretty Dump Cross References
by LanX (Saint) on Nov 28, 2014 at 23:54 UTC
    > Is there something better

    what is "better"?

    There are plenty of options to format the output, you should read the documentation and play around.

    > or maybe an option to get a dump without reference notation

    This looks promising

    $Data::Dumper::Deepcopy or $OBJ->Deepcopy([NEWVAL]) Can be set to a boolean value to enable deep copies of structures. Cro +ss-referencing will then only be done when absolutely essential (i.e. +, to break reference cycles). Default is 0.

    You may also want to have a look at Data::Dump which comes with nicer defaults.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      Thx

      Of course, I read the docs of Data::Dumper more than twice, and tried around some options, but did not understand some parts. Examples would say more than hundred words.

Re: Pretty Dump Cross References
by Perlbotics (Archbishop) on Nov 28, 2014 at 23:56 UTC

    Perhaps Data::Dump gives you terse string representations that are easier to read and compare? Test::Differences might be useful to compare data structures and highlight differences automatically.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1108674]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found