Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Getting a variable name from a reference

by koolade (Pilgrim)
on Mar 05, 2002 at 18:18 UTC ( #149458=note: print w/replies, xml ) Need Help??


in reply to Getting a variable name from a reference

You can use symbolic references:

our %hash1 = ("A"=>1); our %hash2 = ("B"=>2); foreach my $hashref ('hash1', 'hash2') { no strict 'refs'; print "$hashref:",(join ",",sort keys %{$hashref}),"\n"; }

Note that it won't work on variables declared with my(). From perlref:

Only package variables (globals, even if localized) are visible to symbolic references. Lexical variables (declared with my()) aren't in a symbol table, and thus are invisible to this mechanism.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2022-08-16 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?