Just add the code below to your main program, and you can do the following:
or, if you don't have objects but want to quickly dump a data-structure:my $foo = new Foo; $foo->dump; # dumps automatically to STDERR print $foo->dump; #dumps to STDOUT print FOO $foo->dump; # dumps to filehandle FOO
a->dump( $foo ); # dumps automatically to STDERR print a->dump( $foo ); #dumps to STDOUT print FOO a->dump( $foo ); # dumps to filehandle FOO
I wonder whether it would make sense to make a "dump" pragma for this and upload to CPAN.
sub UNIVERSAL::dump { # Obtain the object / class # Make sure that we have Data::Dumper # Return Dumper output if not in void context # Send Dumper output to STDERR otherwise my $self = shift; require Data::Dumper; return Data::Dumper::Dumper( @_ ? @_ : $self ) if defined wantarra +y; print STDERR Data::Dumper::Dumper( @_ ? @_ : $self ); } #UNIVERSAL::dump
In reply to Quick Dumper by liz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |