perlfunc
gods
<P>
caller - get context of the current subroutine call
<P>
<HR>
<P>
caller
<FONT SIZE=-1>EXPR</FONT>
<P>
caller
<P>
<HR>
<P>
Returns the context of the current subroutine call. In scalar context,
returns the caller's package name if there is a caller, that is, if we're
in a subroutine or [perlfunc:eval|eval()] or [perlfunc:require|require()], and the undefined value otherwise. In list context, returns
<P>
<PRE> ($package, $filename, $line) = caller;
</PRE>
<P>
With
<FONT SIZE=-1>EXPR,</FONT> it returns some extra information that the debugger uses to print a stack trace. The value of
<FONT SIZE=-1>EXPR</FONT> indicates how many call frames to go back before the current one.
<P>
<PRE> ($package, $filename, $line, $subroutine,
$hasargs, $wantarray, $evaltext, $is_require) = caller($i);
</PRE>
<P>
Here <CODE>$subroutine</CODE> may be <CODE>"(eval)"</CODE> if the frame is not a subroutine call, but an [perlfunc:eval|eval()]. In such a case additional elements <CODE>$evaltext</CODE> and
<CODE>$is_require</CODE> are set: <CODE>$is_require</CODE> is true if the frame is created by a
[perlfunc:require|require] or [perlfunc:use|use] statement, <CODE>$evaltext</CODE> contains the text of the
<CODE>eval EXPR</CODE> statement. In particular, for a <CODE>eval BLOCK</CODE> statement,
<CODE>$filename</CODE> is <CODE>"(eval)"</CODE>, but <CODE>$evaltext</CODE> is undefined. (Note also that each [perlfunc:use|use] statement creates a [perlfunc:require|require] frame inside an <CODE>eval EXPR</CODE>) frame.
<P>
Furthermore, when called from within the
<FONT SIZE=-1>DB</FONT> package, caller returns more detailed information:
it sets the list variable <CODE>@DB::args</CODE> to be the arguments with which the subroutine was invoked.
<P>
Be aware that the optimizer might have optimized call frames away before
[perlfunc:caller|caller()] had a chance to get the information. That means that [perlfunc:caller|caller(N)]
might not return information about the call frame you expect it do, for
<CODE>N > 1</CODE>. In particular, <CODE>@DB::args</CODE> might have information from the previous time [perlfunc:caller|caller()] was called.
<HR>