Minimum
Viable
Perl
This book is a work in progress. Subscribe to get new chapters in your inbox.
Chapter 6. Debugging

6.1. Examining data structures

There are lots of good modules that make this easy. I recommend Data::Printer.

Example code:

eric@eric:~ $ cat foo.pl 
#!/usr/bin/env perl
use strict;
use warnings;
use DDP;
my $data_structure = {
 scalar => 42,
 listref => [1, 2, 3],
 hashref => {a => 1, b => 2, c => 3},
 coderef => sub { print "hello\n" },
};
p $data_structure;

On the command line:

eric@eric:~ $ perl foo.pl 
\ {
 coderef sub { ... },
 hashref {
 a 1,
 b 2,
 c 3
 },
 listref [
 [0] 1,
 [1] 2,
 [2] 3
 ],
 scalar 42
}

AltStyle によって変換されたページ (->オリジナル) /