<?xml version="1.0" encoding="windows-1252"?>
<node id="359" title="perlfunc:caller" created="1999-08-24 18:43:39" updated="2005-08-13 04:18:43">
<type id="119">
perlfunc</type>
<author id="114">
gods</author>
<data>
<field name="doctext">
</field>
<field name="name">

&lt;P&gt;
caller - get context of the current subroutine call

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="synopsis">

&lt;P&gt;
caller 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt;

&lt;P&gt;
caller

&lt;P&gt;
&lt;HR&gt;
</field>
<field name="description">

&lt;P&gt;
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

&lt;P&gt;
&lt;PRE&gt;    ($package, $filename, $line) = caller;
&lt;/PRE&gt;
&lt;P&gt;
With 
&lt;FONT SIZE=-1&gt;EXPR,&lt;/FONT&gt; it returns some extra information that the debugger uses to print a stack trace. The value of 
&lt;FONT SIZE=-1&gt;EXPR&lt;/FONT&gt; indicates how many call frames to go back before the current one.

&lt;P&gt;
&lt;PRE&gt;    ($package, $filename, $line, $subroutine,
     $hasargs, $wantarray, $evaltext, $is_require) = caller($i);
&lt;/PRE&gt;
&lt;P&gt;
Here &lt;CODE&gt;$subroutine&lt;/CODE&gt; may be &lt;CODE&gt;&amp;quot;(eval)&amp;quot;&lt;/CODE&gt; if the frame is not a subroutine call, but an [perlfunc:eval|eval()]. In such a case additional elements &lt;CODE&gt;$evaltext&lt;/CODE&gt; and
&lt;CODE&gt;$is_require&lt;/CODE&gt; are set: &lt;CODE&gt;$is_require&lt;/CODE&gt; is true if the frame is created by a
[perlfunc:require|require] or [perlfunc:use|use] statement, &lt;CODE&gt;$evaltext&lt;/CODE&gt; contains the text of the
&lt;CODE&gt;eval EXPR&lt;/CODE&gt; statement. In particular, for a &lt;CODE&gt;eval BLOCK&lt;/CODE&gt; statement,
&lt;CODE&gt;$filename&lt;/CODE&gt; is &lt;CODE&gt;&amp;quot;(eval)&amp;quot;&lt;/CODE&gt;, but &lt;CODE&gt;$evaltext&lt;/CODE&gt; is undefined. (Note also that each [perlfunc:use|use] statement creates a [perlfunc:require|require] frame inside an &lt;CODE&gt;eval EXPR&lt;/CODE&gt;) frame.

&lt;P&gt;
Furthermore, when called from within the 
&lt;FONT SIZE=-1&gt;DB&lt;/FONT&gt; package, caller returns more detailed information:
it sets the list variable &lt;CODE&gt;@DB::args&lt;/CODE&gt; to be the arguments with which the subroutine was invoked.

&lt;P&gt;
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
&lt;CODE&gt;N &amp;gt; 1&lt;/CODE&gt;. In particular, &lt;CODE&gt;@DB::args&lt;/CODE&gt; might have information from the previous time [perlfunc:caller|caller()] was called.

&lt;HR&gt;
</field>
</data>
</node>
