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 ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday July 30, 2004
07:42 PM

Inspiration from Damian -- Data::Dumper::Simple

[ #20153 ]

Damian's talks have again inspired me. I've started working on my AI life code again, but first I've taken a detour. This sucks:

use Data::Dumper;
print Dumper($foo, $bar, $baz, \%hash);

It works great, but it sucks because I have, on many occasions, forgotten the order of the arguments and I have to bounce back to the code to try and remember what I dumped out. Of course, it's "simple" to fix that with a little known use of Data::Dumper:

print Data::Dumper->Dump(
    [$foo, $bar, $baz, \%hash],
    [qw/*foo *bar *baz *hash/]

That will conveniently name all of the variables for you instead of using the cryptic $VAR1, $VAR2, etc. It's still too much typing, though, and if I accidentally transpose a couple of variable names in the second array ref, I get very confused.

So I'm writing a new module which will, hopefully, go to the CPAN soon.

use Data::Dumper::Simple;
print Dumper($scalar, @array, %hash);

And that prints something like:

$scalar = 'Ovid';
@array = (
%hash = (
          'some' => 'data',
          'goes' => 'here'

Of course, you may have noticed that I didn't put a backslash before the variable names in the argument list. This is not a typo. And I have it working right now. I have more work to do to get it robust, but so far, it's pretty cool.

And if you forget that references aren't needed, that's okay, because it still works like this:

use Data::Dumper::Simple;
print Dumper($scalar, \@array, \%hash);

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.