5.1. Dumping Your Data

That is all well and good for scalars and arrays, but it won't even handle hashes, let alone complex lists of lists. A good way to deal with those is to use the Dumper function in the Data::Dumper module which will let you print out, nicely formatted, anything you give it, no matter how complex:

use Data::Dumper;
# set %state from some database or flat file
warn Dumper(\%state);

which produces

$VAR1 = {
          'WI' => {
                    'BIRD'         => 'Robin',
                    'NAME'         => 'Wisconsin',
                    'LARGEST_CITY' => 'Milwaukee',
                    'CAPITAL'      => 'Madison',
                    'FLOWER'       => 'Wood Violet'
                  },
          'MS' => {
                    'BIRD'         => 'Mockingbird',
                    'NAME'         => 'Mississippi',
                    'LARGEST_CITY' => 'Jackson',
                    'CAPITAL'      => 'Jackson',
                    'FLOWER'       => 'Magnolia'
                  },
[...]

Note that we passed a reference to the ...

Get Perl Debugged now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.