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>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.