Skrevet av Emne: Perl: Who called me?  (Lest 2487 ganger)

ATC

  • Gjest
Perl: Who called me?
« på: 16. Januar 2009, 16:21 pm »
  • [applaud]0
  • [smite]0
  • When troubleshooting perl code, is it possible to see where a subroutine was called from?



    ATC

    • Gjest
    [Solved] Perl: Who called me?
    « Svar #1 på: 16. Januar 2009, 16:21 pm »
  • [applaud]0
  • [smite]0
  • 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