Ano-Tech Computers
Enter keyword:

Perl: Who called me?
Problem:
When troubleshooting perl code, is it possible to see where a subroutine was called from?
 
Solution:
Yes. The proper way to do this is using the Carp module. However, you can examine the code stack via the caller() function. Implement your own full-blown stack tracer, or simply use code such as this to get a quick clue:

my ($pkg, $file, $line, $sub) = caller(0); print "$sub was called from $pkg in $file line $line\n";

The output will look something like this:

main::subroutine called from main in ./callertest line 8


 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles