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.