http://www.perlmonks.org?node_id=831351


in reply to Re^2: Dumping variables but DRY and simple
in thread Dumping variables but DRY and simple

eval() is needed only when you want a deep copy.
use Data::Dump qw( pp dd ); my $ref = [ 'foo', 'bar', { asd => 1, qwe => 2 } ]; # pp() called in void context prints to STDERR pp $ref; # prints: ["foo", "bar", { asd => 1, qwe => 2 }] # dd() called in void context prints to STDOUT dd $ref; # named printing is still not DRY, but much better than: # print Data::Dumper->Dump( [$ref], ['*ref'] ); print '$ref = ', pp($ref), "\n"; # prints: $ref = ["foo", "bar", { asd => 1, qwe => 2 }] # eval() for a deep copy my $deep_copy = eval pp($ref); pp $deep_copy;
The printing format is a lot more readable than Data::Dumper's default. However beware that Data::Dump is not among the core modules.

Replies are listed 'Best First'.
Re^4: Dumping variables but DRY and simple
by LanX (Saint) on Mar 27, 2010 at 15:05 UTC
    # named printing is still not DRY, but much better than: # print Data::Dumper->Dump( [$ref], ['*ref'] ); print '$ref = ', pp($ref), "\n";

    yeah but thats core...

    use Data::Dumper qw/Dumper/; print '$ref = ', Dumper($ref), "\n";

    So really a big gain if it's not DRY?

    Cheers Rolf

      When used during development (when Data::Dump should be installed only on my machine) I think every saved keystroke is a big gain. Although when I want to distribute the resulting code (eg. using for a deep copy, not just debug printing) then it is not.