Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://149361]
NodeReaper power washes the cellar floor

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-12-12 19:01 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (335 votes). Check out past polls.