Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: data dumper question

by Marshall (Canon)
on Sep 13, 2016 at 04:30 UTC ( [id://1171632]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found