in reply to Re^2: data dumper question
in thread data dumper question

Hi Todd,

I see from Need help with loop syntax errors, that you like to experiment. I suggest that you do more of the same with Data::Dumper to empirically see what it does with various data structures.

In general you give Dumper a reference to any arbitrary structure and it figures out how to display it.

Here is some "play" code to get you started:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @data = qw( 7 8 9); my $dataref = \@data; #create reference to data array my $string = 'this is string'; print Dumper \@data; #dump using reference to @data =PRINTS $VAR1 = [ '7', '8', '9' ]; =cut print Dumper $dataref; #dump using scalar reference =PRINTS $VAR1 = [ '7', '8', '9' ]; =cut print Dumper @data; =PRINTS $VAR1 = '7'; $VAR2 = '8'; $VAR3 = '9'; =cut print Dumper $string; =PRINTS $VAR1 = 'this is string'; =cut print Dumper \$string; =PRINTS $VAR1 = \'this is string'; =cut __END__ I used a feature of Perl called perlpod - the "Plain Old Documentation +" commands to interleave multi-line printouts into the code. That is not what this is normally used for, but you will sometimes see this techni +que on PM as a way to make the code and the printout all "one Perl file" t +hat can be executed.
There is more than one module that can dump data, but Data::Dumper is "core" meaning that it is included in all Perl distributions and you can just assume that it is there without having to install anything. Have fun experimenting.