Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Data::Dumper in a nutshell?

by trs80 (Priest)
on Feb 08, 2002 at 00:59 UTC ( [id://144000]=note: print w/replies, xml ) Need Help??


in reply to Data::Dumper in a nutshell?

Data::Dumper in a nutshell for debugging/learning.

In some ways I see Data::Dumper as a debugging tool, yet it has many uses beyond.

I most frequently use the exported Dumper function. You feed it a data structure (array,hash,etc) or a complex data structure (hashes and arrays multiple levels deep in any combination, objects etc.) and it will return the complete contents to you. This makes object debugging much easier for me because often times the issue is in the fact that an attribute of object didn't get set correctly. With Dumper you can do this:
use Data::Dumper; $hashref = { key1 => { more => 'less' }, key2 => { help => 'stop' }, key3 => { wow => [ 'list_element_0', '1' , '2' ] }, }; print Dumper($hashref);

That will print what you already know since you created the structure, but what if you are getting back something that you are not sure of the contents on? This is where it comes in handy for both debugging and sometimes better understanding the contents in an object.
Like so ( i am using code from an earlier post by artist ):
use Data::Dumper; use Parse::RecDescent; my $grammer = q{ record: id name id: m[(.{6})] { print "id => $1 " if $1 } name: m[(.*)] { print "name => $1 "; } }; my $parser = Parse::RecDescent->new($grammer); print Dumper($parser);

That will show you the complete data structure of a newly created object.

I feel that the docs for Data::Dumper don't really make it clear how you would apply this module for someone that isn't doing full time development. Once you see how it is applied it will most likely become a very valuable debug utility for anyone working with hidden (dynamic) data structures, which should be most everyone I hope.

Log In?
Username:
Password:

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

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

    No recent polls found