Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: get name of lexical variable

by ysth (Canon)
on Jul 12, 2009 at 18:03 UTC ( #779389=note: print w/ replies, xml ) Need Help??


in reply to Re: get name of lexical variable
in thread get name of lexical variable

PadWalker provides a var_name function that takes the reference and does that for you. It's even more reliable than looping over the lexicals, when the lexical you want is hidden:

#!/usr/bin/perl -l use strict; use warnings; use PadWalker ":all"; sub foo { my $x; for ($x) { my $x; bar(\$_); } } sub bar { print var_name(1, $_[0]); # works my $vars = peek_my(1); print grep $vars->{$_} == $_[0], keys %$vars; # doesn't work unle +ss 2nd my $x is commented out } foo();


Comment on Re^2: get name of lexical variable
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-10-20 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (72 votes), past polls