Re: Perl Special Variable Containing the name of the method currently in?



Nigel <nigelstuart@xxxxxxxxx> wrote in news:de8822a9-7087-4006-a8ef-
fd8c4b7e758a@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:

Just out of curiosity.
Is there a way to get the name of the subroutine Perl is currently in
when it is running?
For example, if I have a subroutine declared with the name sub
helloWorld, is there any way from within that subroutine to
programmatically get 'helloWorld' without having to hardcode it?

#!/usr/bin/perl

use strict;
use warnings;

sub whatismyname { (caller 1)[3] }

sub iknowmyname {
my $name = whatismyname();

print "My name is '$name'\n";
}

iknowmyname();

__END__

Make sure to read perldoc -f caller

Sinan

--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
.



Relevant Pages