On Wed, Jun 1, 2011 at 6:07 PM, eventual <[email protected]> wrote:
> use Data::Dumper;
>
> Hi,
> Can someone give me a few examples on the purpose of use Data::Dumper;
> I tried reading but I could not understand.
> Thanks
use Data::Dumper;
simply tells perl to load the Data::Dumper module. You can then use the
module to well dump data. :-)
Try the following, create a complex data structure something like this:
use Data::Dumper;
my $complex = [ { 'value1' => 'key1', 'value2' => [ 1, 2, 3, 4, 5 ] },
'Array value 2', '03', [ 'String 1', 'String 2', 'String 3' ], ];
print Dumper $complex;
and you will see something like this:
$VAR1 = [
{
'value1' => 'key1',
'value2' => [
1,
2,
3,
4,
5
]
},
'Array value 2',
'03',
[
'String 1',
'String 2',
'String 3'
]
];
Now it might seem silly at first but if you are dealing with large and
complex data structures that have a mix of arrays, hashs, strings,
references to data structures etc.. then you will soon come to love the
Data::Dumper for its very helpful output.
If you are not sure about loading external modules in perl please have a
look at: http://perl-begin.org/tutorials/perl-for-newbies/part3/ which will
give you a good beginner guide to what modules are and what they are used
for etc.
Regards,
Rob