Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to get the name from a reference

by Marshall (Prior)
on Mar 30, 2009 at 20:09 UTC ( #754241=note: print w/ replies, xml ) Need Help??


in reply to How to get the name from a reference

I second ikegami's comment: what is the purpose?

With Perl there are amazing things that you can discover about what is going on in a sub. Just some simple example code is shown below. I am unsure as to what you want.

#!/usr/bin/perl -w use strict; print "testing main\n"; x(); sub x { print "In sub x\n"; print " I am: ", WHOamI(), "\n"; SubLevel2(); } sub SubLevel2 { print "in sub SubLevel2\n"; print " I am: ", WHOamI(), "\n"; print " I was called by ", WHOwasI(),"\n"; } sub WHOamI { (caller(1))[3] }; #returns name of the #sub that called this sub sub WHOwasI { (caller(2))[3] }; #returns name of the parent of #the sub that called this sub __END__ #prints testing main In sub x I am: main::x in sub SubLevel2 I am: main::SubLevel2 I was called by main::x


Comment on Re: How to get the name from a reference
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2015-07-31 04:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls