Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Dumping variables but DRY and simple

by rubasov (Friar)
on Mar 27, 2010 at 14:16 UTC ( #831343=note: print w/ replies, xml ) Need Help??


in reply to Dumping variables but DRY and simple

Have you seen Data::Dump::pp? It eliminates the $VARn ugliness.


Comment on Re: Dumping variables but DRY and simple
Download Code
Re^2: Dumping variables but DRY and simple
by LanX (Canon) on Mar 27, 2010 at 14:34 UTC
    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

      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

      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://831343]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-09-20 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls