Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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]
[thao4]: thao4
[hippo]: Indeed you are.
[thao4]: Hi all, I am new in perl. I need do somthing in perl: exemple: - search a patern "CADRE 1.1 CPU" in one file.txt - incremente +30 lines from the line with the patern found - replace the patern "Model Regle" by "Heath Rule A" in this new line (30 line
[marto]: good morning all
[hippo]: Welcome. Tell me, have you read perlintro? That's a great place to start.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2018-02-21 09:42 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (276 votes). Check out past polls.