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).
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);
The actual printout looks like this:
>
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
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)?
--
Ronald Fischer <ynnor@mm.st>