obtaining name of the current subroutine

M

Michael Preminger

Hello!

Is there a constant, literal, function or any other construct that
returns the name of the subroutine from which it is invoked?

I would like something like this

sub <any_name>{
print "I am in: <CONSTRUCT RETURNING SUBROUTINE NAME>"

}

Thanks

Michael
 
V

Vetle Roeim

[...]
Is there a constant, literal, function or any other construct that
returns the name of the subroutine from which it is invoked?

This seems to work:

sub foo {
my ($package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask) =
caller(0);

print $subroutine, "\n";
}



[...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top