[Pdx-pm] Newbie question ... built-in for subroutine name?
Tkil
tkil at scrye.com
Thu Jul 25 18:17:24 CDT 2002
To amplify my previous response:
| #!/usr/bin/perl -w
|
| use strict;
|
| sub squawk
| {
| my ($sub) = (caller 1)[ 3 ];
| $sub ||= 'main';
| my ($file, $line) = (caller 0)[ 1, 2 ];
| print "squawk: called from $sub ($file\: $line)\n";
| }
|
| sub foo { squawk(); }
|
| print "in main\n";
| squawk();
|
| foo();
|
| exit 0;
Which gives me:
| $ ./show-caller
| in main
| squawk: called from main (./show-caller: 16)
| squawk: called from main::foo (./show-caller: 13)
I've used this to do a custom version of carp/cluck before (perldoc
Carp). It's a bit annoying that we have to look at two different
"caller" levels to get information about one point, but whatever
works...
t.
More information about the Pdx-pm-list
mailing list