Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Dumping variables but DRY and simple

by LanX (Canon)
on Mar 27, 2010 at 14:34 UTC ( #831344=note: print w/ replies, xml ) Need Help??


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

yes .... I saw it some days ago...but

Returns a string containing a Perl expression. If you pass this string to Perl’s built-in eval() function it should return a copy of the arguments you passed to dump().

didn't encourage me a lot, wrapping all in evals is not what I really wanted.

But maybe I'm wrong, can you show me example code?

Cheers Rolf


Comment on Re^2: Dumping variables but DRY and simple
Re^3: Dumping variables but DRY and simple
by rubasov (Friar) on Mar 27, 2010 at 14:58 UTC
    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.
      # 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.
Re^3: Dumping variables but DRY and simple
by ikegami (Pope) on Mar 27, 2010 at 15:59 UTC
    Same goes for Data::Dumper. If you want to reify the structure, you need to use eval. As far as I'm concerned, they are debugging tools, not storage tools.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://831344]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-07-05 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls