in reply to Re^3: caller() mystery
in thread caller() mystery
caller(1) returns info about f's caller
If this is the case, I would understand why my approach failed. But then I don't understand why in my original program, caller(1) (executed from within _format_caller) delivered
That is, it says "the caller is main::f". This is _format_caller's caller, NOT f's caller. Actually that's why I had concluded that counting would start at 1. And indeed, from the command line:main,U:\develsv\ARTS\playground\callertest.pl,16,main::f,1,,,,2,UUUUUU +UUUUU
gives main::a (that is, caller 0 says "who I am", i.e. which function is invoking caller).perl -lwe 'sub a{print((caller 0)[3])};sub b{a()};sub c{b()}; c'
gives main::b (that is, caller 1 says who has called me)perl -lwe 'sub a{print((caller 1)[3])};sub b{a()};sub c{b()}; c'
gives main::c (that is, the caller of main::b), but forperl -lwe 'sub a{print((caller 2)[3])};sub b{a()};sub c{b()}; c'
I would have expected to get information about the caller of main::c, which is the main program (not the shell), but there is none.perl -lwe 'sub a{print((caller 3)[3])};sub b{a()};sub c{b()}; c'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: caller() mystery
by JavaFan (Canon) on Sep 26, 2008 at 10:55 UTC |