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
require) and the undefined value
otherwise. In list context, returns
- # 0 1 2
- ($package, $filename, $line) = caller;
With EXPR, it returns some extra information that the debugger uses to print a stack trace. The value of EXPR indicates how many call frames to go back before the current one.
- # 0 1 2 3 4
- ($package, $filename, $line, $subroutine, $hasargs,
- # 5 6 7 8 9 10
- $wantarray, $evaltext, $is_require, $hints, $bitmask, $hinthash)
- = caller($i);
Here $subroutine may be
if the frame is not a subroutine
call, but an
eval. In such a case additional elements $evaltext and
is true if the frame is created by a
use statement, $evaltext contains the text of the
statement. In particular, for an
, but $evaltext is undefined. (Note also that
use statement creates a
require frame inside an
frame.) $subroutine may also be
if this particular
subroutine happens to have been deleted from the symbol table.
is true if a new instance of
was set up for the frame.
contain pragmatic hints that the caller was
compiled with. The
values are subject to change
between versions of Perl, and are not meant for external use.
is a reference to a hash containing the value of
caller was compiled, or
was empty. Do not modify the values
of this hash, as they are the actual values stored in the optree.
Furthermore, when called from within the DB package in
list context, and with an argument, caller returns more
detailed information: it sets the list variable
to be the
arguments with which the subroutine was invoked.
Be aware that the optimizer might have optimized call frames away before
caller had a chance to get the information. That means that
might not return information about the call frame you expect it to, for
N > 1
. In particular,
might have information from the
caller was called.
Be aware that setting
is best effort, intended for
debugging or generating backtraces, and should not be relied upon. In
contains aliases to the caller's arguments, Perl does
not take a copy of
will contain modifications the
subroutine makes to
or its contents, not the original values at call
, does not hold explicit references to its
elements, so under certain cases its elements may have become freed and
reallocated for other variables or temporary values. Finally, a side effect
of the current implementation is that the effects of
normally be undone (but not
or other splicing, and not if a
has been taken, and subject to the caveat about reallocated
is actually a hybrid of the current state and
initial state of
. Buyer beware.