whats the purpose of use Data::Dumper;

--0-1335162251-1306944465=:4197
Content-Type: text/plain; charset=us-ascii

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
--0-1335162251-1306944465=:4197--
eventual [ Mi, 01 Juni 2011 18:07 ] [ ID #2060372 ]

Re: whats the purpose of use Data::Dumper;

--0015175cb9f625c9a204a4a8da1c
Content-Type: text/plain; charset=UTF-8

On Wed, Jun 1, 2011 at 6:07 PM, eventual <eventualdeath [at] yahoo.com> 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

--0015175cb9f625c9a204a4a8da1c--
Rob Coops [ Mi, 01 Juni 2011 18:16 ] [ ID #2060373 ]

Re: whats the purpose of use Data::Dumper;

On Wed, Jun 01, 2011 at 09:07:45AM -0700, eventual 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

Data::Dumper is a useful modules for converting perl data structures into=
a
string for printing. It can be used for debugging, understanding how
somebody else's code works, tranffering information, etc. The full
docs for the module can be found at
<http://search.cpan.org/perldoc?Data::Dumper>.

Here's a simple example:
#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use Data::Dumper;

my [at] foo =3D ( 'one', 'two', 'three' );
my %bar =3D ( 'redfish' =3D> 'bluefish', 'onefish' =3D> 'twofish' );

my $more_complex =3D [
{ foo =3D> 'bar', 'baz' =3D> 'biz' },
'two',
{ a =3D> 'b', c =3D> [ 'one', 'two', 'three' ] }
];

say Data::Dumper->Dump( [ \ [at] foo, \%bar, $more_complex ],
[ 'foo', 'bar', 'more_complex' ] );

Produces this output:

$foo =3D [
=A0=A0=A0=A0=A0=A0=A0=A0=A0'one',
=A0=A0=A0=A0=A0=A0=A0=A0=A0'two',
=A0=A0=A0=A0=A0=A0=A0=A0=A0'three'
=A0=A0=A0=A0=A0=A0=A0];
$bar =3D {
=A0=A0=A0=A0=A0=A0=A0=A0=A0'onefish' =3D> 'twofish',
=A0=A0=A0=A0=A0=A0=A0=A0=A0'redfish' =3D> 'bluefish'
=A0=A0=A0=A0=A0=A0=A0};
$more_complex =3D [
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'baz' =3D> 'b=
iz',
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'foo' =3D> 'b=
ar'
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0},
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0'two',
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'c' =3D> [
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=
=A0=A0=A0=A0'one',
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=
=A0=A0=A0=A0'two',
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=
=A0=A0=A0=A0'three'
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 =A0=A0=A0=A0=A0=
=A0=A0],
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 'a' =3D> 'b'
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0}
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0];

--- END --

Hopefully this is useful.

Mike

--
Michael
michael [at] thegrebs.com
M: +1-562-MIKEGRB

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Michael Greb [ Mi, 01 Juni 2011 20:12 ] [ ID #2060375 ]
Perl » gmane.comp.lang.perl.beginners » whats the purpose of use Data::Dumper;

Vorheriges Thema: accessing array
Nächstes Thema: Perl Beginnners