P is for Practical | |
PerlMonks |
Re: Re: Getting a variable name from a referenceby erikharrison (Deacon) |
on Mar 05, 2002 at 13:31 UTC ( [id://149359]=note: print w/replies, xml ) | Need Help?? |
You're right - it can't be done without saving the name of the name of the variable and some additional jiggery pokery. At least it can't be done with a hard reference like this. The reason it can't be done is because a hard reference is just and address - so the "thingie" that the address points to might have no varable name, such as an anonymous hash:
Additionally, a varable might have more than one name, if it has aliases. Back in Perl 4 (which I've never used) there were no hard refs, so you had to use variable - name - plus eval tricks to do reference type stuff. This might do what you want it to (warning - untested code):
But these kinds of eval tricks I'm not used to - and you probably shouldn't use them anyway. Also, you can't print out a memory address here, unless you add in a pair of hard refs. Cheers,Erik
In Section
Seekers of Perl Wisdom
|
|