Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Data::Dumper

by geektron (Curate)
on Sep 09, 2000 at 03:28 UTC ( #31714=modulereview: print w/ replies, xml ) Need Help??

Item Description: takes a variable ( or reference to a variable) and 'unrolls' or dumps it out for inspection

Review Synopsis: invaluable for object design and debugging complicated data structure

Data::Dumper is in the standard Perl distribution. it's probably the easiest module to use, just issue a 'use Data::Dumper' call, and then either print to STDOUT ( with 'print Dumper \@foo ') or stick into some html used by an application ( i prefer to wrap it in <pre> tags, so the output isn't mangled.) Data::Dumper also works keenly with objects, and gives you the class into which your variable is blessed. (with makes debugging object relations really quick.)

Comment on Data::Dumper
RE (tilly) 1: Data::Dumper
by tilly (Archbishop) on Sep 11, 2000 at 03:42 UTC
    Stupid Data::Dumper trick. Set $Data::Dumper::Indent to 1 and dump a reference to a data structure. What you get is readable to humans, and makes a very convenient format for a configuration file. Just do the file to read the configuration. No work definining a format. No worries about whether or not everything is escaped...
RE: Data::Dumper
by lachoy (Parson) on Oct 18, 2000 at 03:13 UTC

    Big 'me too' along with tilly for using Data::Dumper for configuration files.

    In addition I must say that my debugging life would be much more painful in a world without Data::Dumper. Curious about what's in that hairy list of hashes of lists of hashes? Just Dump It!

    All hail Data::Dumper!

      However, your curiosity for the contents of code refs will never be satisfied, nor will you serialize them to disk, or ever de-serialize them and resurrect them, for this is not possible in Perl5. And probably not Perl 6.

      But it is a serious shortcoming that doesn't exist in many other scripting languages.

      Prince "Why cant we preview replies?!" Pawn

RE: Data::Dumper (Adam: Sample Usage)
by Adam (Vicar) on Oct 27, 2000 at 23:00 UTC
    I'm always forgeting the way to get Data::Dumper to print a hash and put the name of the hash in-place of the "$VAR". So this is as good a place as any to stick it where I can find it quickly, and other people can see an example usage.
    use strict; use Data::Dumper; my %hash = ( 'some' => 'stuff' ); print Data::Dumper->Dump([\%hash], ["hashname"]), $/;

      Here's an example of how I use Data::Dumper, on one line, during debugging. It produces a pretty clean output of the data structure:

      print Data::Dumper->new([\%hash],[qw(hash)])->Indent(3)->Quotekeys(0)->Dump;
RE: Data::Dumper
by Anonymous Monk on Nov 10, 2000 at 06:51 UTC
    Another Data::Dumper trick- For quick and dirty state persistence over multiple invocations of a program, use a single hash for all your state info. Dumper() a reference to it into a file when the program exits, and require() that file the next time the program starts up. booom. You're right back where you left off.
Re: Data::Dumper
by premchai21 (Curate) on May 07, 2001 at 21:10 UTC
      Look At Data::TreeDumper. Muchhh more readable.

Back to Reviews

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: modulereview [id://31714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (13)
As of 2014-07-25 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (173 votes), past polls