LANTI has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
for a debugging-sub I would like to pass the name of a variable to the sub. How is this possible?
What I have so far (untested yet):
say sdump($some_ref); sub sdump { my $ref = shift || croak('nothing to dump - missing ref'); my $depth = shift || 2; local $Data::Dumper::Maxdepth = $depth; return 'Dump of $var_name: ' . "\n" . Dumper($ref) }
How can I get the $var_name('$some_ref' in this exemple) into the sub?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: passing a variables name to a subroutine
by moritz (Cardinal) on Feb 18, 2011 at 12:13 UTC | |
by LANTI (Sexton) on Feb 18, 2011 at 13:55 UTC | |
by moritz (Cardinal) on Feb 18, 2011 at 15:23 UTC | |
by jdporter (Paladin) on Jul 19, 2012 at 15:40 UTC | |
|
Re: passing a variables name to a subroutine
by Anonymous Monk on Feb 18, 2011 at 14:14 UTC |