Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Getting a variable name from a reference

by MZSanford (Curate)
on Mar 05, 2002 at 13:46 UTC ( [id://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

Replies are listed 'Best First'.
(tye)Re: Getting a variable name from a reference
by tye (Sage) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://149361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found