Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: passing a variables name to a subroutine

by LANTI (Sexton)
on Feb 18, 2011 at 13:55 UTC ( [id://888901]=note: print w/replies, xml ) Need Help??


in reply to Re: passing a variables name to a subroutine
in thread passing a variables name to a subroutine

hmh ... seems not to work, if the dumped ref is a lexical variable in production-code. For the moment I live with this solution - not very elegant, because most of the time the identifying string will be same as the var-name:

say sdump($pout, '$pout'); sub sdump { my $ref = shift || croak('nothing to dump - missing ref'); my $name = shift || 'n/a'; my $depth = shift || 2; local $Data::Dumper::Maxdepth = $depth; return "Dump of $name:\n" . Dumper($ref); }

Any idea, how to call it this way?

sdump('$pout');

Replies are listed 'Best First'.
Re^3: passing a variables name to a subroutine
by moritz (Cardinal) on Feb 18, 2011 at 15:23 UTC
    hmh ... seems not to work, if the dumped ref is a lexical variable in production-code.

    With which code did it not work? Did you try PadWalker as I suggested? How the the production code differ from the test code?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://888901]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-18 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found