Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Getting a variable name from a reference

by MZSanford (Curate)
on Mar 05, 2002 at 13:46 UTC ( #149361=note: print w/ replies, xml ) Need Help??


in reply to Getting a variable name from a reference

Let me start by saying, this should never be done. never. Ok, that aside, i thought of a way that might work.
     You could loop through the %main:: hash, and compare the values of each name-spaces hash variable. Something like this (untested code and idea):

%hash1 = ('A' => 1); $href = \%hash1; foreach my $name (keys %main::) { if ($href eq \%{"main::$name"}) { print "Hash ref is for %",$name,"\n"; } }

Please note, i do not condone this behavior.
from the frivolous to the serious


Comment on Re: Getting a variable name from a reference
Select or Download Code
(tye)Re: Getting a variable name from a reference
by tye (Cardinal) on Mar 05, 2002 at 14:55 UTC

    Note that variables declared with my are not in any symbol table. So this won't work for the code used in the original question.

            - tye (but my friends call me "Tye")
Re: Re: Getting a variable name from a reference
by shotgunefx (Parson) on Mar 05, 2002 at 14:57 UTC
    I agree that it's probably not a good thing to do but, If you don't find it in the package, ie.. it's a lexical, you could try PadWalker.

    -Lee

    "To be civilized is to deny one's nature."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2014-12-28 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls