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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quick Dumper
by zentara (Cardinal) on Dec 03, 2003 at 15:44 UTC | |
|
Re: Quick Dumper
by diotalevi (Canon) on Dec 03, 2003 at 13:09 UTC | |
by liz (Monsignor) on Dec 03, 2003 at 13:13 UTC | |
by diotalevi (Canon) on Dec 03, 2003 at 13:40 UTC | |
by liz (Monsignor) on Dec 03, 2003 at 13:49 UTC |