Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I also have placed this question in Q&A subroutine section as I realy _need_ this feature. I've read all related perl manuals and didn't find a way to get a subroutine name from within a subroutine. I think there should be some kind of variable to store a name ( $SUBNAME i.e.). Sorry if I've missed something..

Replies are listed 'Best First'.
RE: Getting subroutine name
by vroom (His Eminence) on Jan 10, 2000 at 09:56 UTC
    use the caller function $this_function=(caller(0))[3]; The array caller returns looks like this: ($package, $filename, $line, $subroutine, $has_args, $wantarray)=caller($i); # 0 1 2 3 4 5 you call caller with a parameter of how many subroutine calls back you want to go... in your case 0