Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name of Current Subroutine? 2

Status
Not open for further replies.

hmerrill

Programmer
Dec 4, 2000
473
US
If I'm coding a subroutine - inside the subroutine is there some perl variable I can refer to that will tell me the name of the subroutine I'm currently in? I keep looking for a $ something variable, but I can't find one that tells me the name of the current subroutine.

Thanks. Hardy Merrill
 
Can't find one.
Is it plausible to make one???

sub this {
$thissub = "this";
...
}

sub that {
$thissub = "that";
...
}

sub hibby {
$thissub = "hibby";
...
}

and so on down the line...


OR if you are creating subroutines on the fly: check out AUTOLOADING. With this method you could use the $AUTOLOAD variable to detect what sub was called (even though it didn't exist)...

--jim
 
(caller(0))[3] returns currentpackage::subname,
e.g., "main::mysub".

If you don't want the package name, you could get
rid of it:

($me = (caller(0))[3]) =~ s/.*://;
 
DAMN! I read about that in the Camel, then forgot about it. Very nice.

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top