rovf has asked for the wisdom of the Perl Monks concerning the following question:
It seems that I haven't understood properly the perldocs of the caller function. My understanding was that with caller(1), I walk up one frame (i.e. get the information about who is calling me), with caller(2) I walk up 2 frames, etc.
But now look at the following example program. _format_caller is called twice; the first time it is supposed to print what is returned by caller(1), the second time caller(2).
The actual printout looks like this:use strict; use warnings; sub _format_caller { my @x=caller($_[0]); print "elements:",scalar(@x),"\n"; print(join(',',@x),"\n"); } sub f { my $level=$_[0]; print "test caller $level\n"; _format_caller($level); } f(1); f(2);
Well, the uninitialized warnings are because some of the elements returned by caller are undef. But why don't I get anything back in the case of caller(2)?> Use of uninitialized value in join or string at U:\develsv\ARTS\playgr +ound\callertest.pl line 7. Use of uninitialized value in join or string at U:\develsv\ARTS\playgr +ound\callertest.pl line 7. Use of uninitialized value in join or string at U:\develsv\ARTS\playgr +ound\callertest.pl line 7. test caller 1 elements:10 main,U:\develsv\ARTS\playground\callertest.pl,16,main::f,1,,,,2,UUUUUU +UUUUU test caller 2 elements:0
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: caller() mystery
by ikegami (Patriarch) on Sep 26, 2008 at 09:47 UTC | |
by rovf (Priest) on Sep 26, 2008 at 10:11 UTC | |
by ikegami (Patriarch) on Sep 26, 2008 at 10:23 UTC | |
by rovf (Priest) on Sep 26, 2008 at 10:41 UTC | |
by JavaFan (Canon) on Sep 26, 2008 at 10:55 UTC | |
Re: caller() mystery
by andreas1234567 (Vicar) on Sep 26, 2008 at 10:17 UTC | |
by rovf (Priest) on Sep 26, 2008 at 10:48 UTC | |
Re: caller() mystery
by JavaFan (Canon) on Sep 26, 2008 at 09:52 UTC |