Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ank (5971)

ank
  (email not shown publicly)

Journal of ank (5971)

Tuesday June 24, 2008
09:47 AM

Data::Dumping code refs

Just another reason to love Data::Dumper which is, in my opinion, the best module in perlland. Pay close attention.

Suppose you have this data structure:

my $ref = { a => sub { print "a"; } };

Data::Dumper dumps it as:

$VAR1 = { 'a' => sub { "DUMMY" } };

Because it doesn't print out sub references. But you can tell it to deparse them (through B::Deparse) by setting $Data::Dumper::Deparse:

use Data::Dumper;
$Data::Dumper::Deparse = 1;

my $ref = { a => sub { print "a"; } };
print Dumper $ref;

produces

$VAR1 = {
 'a' => sub {
  print 'a';
 }
};

I didn't know this feature existed, and was considering creating a new module to mix Data::Dumper and B::Deparse.