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

Ovid on 2004-07-31T00:42:39

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 = (
           'Data',
           'Dumper',
           'Simple',
           'Rocks!'
         );
%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);


quiet suffering

gizmo_mathboy on 2004-07-31T14:08:40

I suffered with that interface, too, but I didn't do anything about it. Way to go. I eagerly await Data::Dumper::Simple (and to look under the hood).

Thanks.

Re:quiet suffering

Ovid on 2004-07-31T19:48:23

Well, you'll be happy to know that an alpha is on its way to the CPAN. In the meantime, you can download it from my site. Let me know what bugs you find (I'm sure there will be some).