Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ank (5971)

  (email not shown publicly)

Journal of ank (5971)

Tuesday June 24, 2008
08:47 AM

Data::Dumping code refs

[ #36764 ]

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;


$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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • see Data::Dump::Streamer
    • Yes, what he said. Data::Dump::Streamer will do Data::Dumper's job plus it'll also dump the closure's data too.

      my %omg = (...);
      sub ... { $omg{...} }
      # Dumps %omg too because it is part of the data
      Dump( \&... );