is there a comfortable and DRY way to dump variables?
I mean neither printing "$VAR1" nor having to repeat the name over and over again, and working with both kinds of variables?
For instance always writing: print Data::Dumper->Dump([\@fontspec],['*fontspec']); is no fun.
I made this hack, which works quite fine so far (ATM for lexicals only):
sub dmp (\[$@%];\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%]\[$@%] +){ # die "to many arguments for dmp()" if @_>10; use PadWalker qw/var_name/; for $struc (@_){ local $,="\n"; my $name=var_name(1, $struc); $name=~s/^[\@\$\%]/\*/; print Data::Dumper->Dump([$struc],[$name]); } }
which called with
dmp @fontspec;
produces the same output:
@fontspec = ( { 'id' => '0', 'family' => 'Helvetica', 'size' => '10' }, { # ... and so on
But I have the uncomfortable feeling of reinventing the wheel...
Cheers Rolf
UPDATE: improved code
UPDATE: hmm maybe Conway's Smart::Comments should be mentioned, but it uses code filters...
In reply to Dumping variables but DRY and simple by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |