Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

caller

Returns information about the calling subroutine’s context.

In scalar context, returns the package name of the calling subroutine. In list context, returns a multi-element list with (at minimum) package, filename, and line number. When called with a numeric argument N, returns information about the Nth stack frame above the current subroutine:

IndexField
0package name
1filename
2line number
3subroutine
4hasargs
5wantarray

Returns undef (scalar) or an empty list if the requested stack depth exceeds the actual call depth. caller(0) returns info from call_stack.last() (the current sub’s frame); caller(1) looks one frame further up.

When the op has WANT bits set to 0 (unknown), the context is inherited from the enclosing call frame, matching perl5 behavior.

Synopsis

my $package = caller;                  # scalar: package name
my ($pkg, $file, $line) = caller;      # list: basic triple
my ($pkg, $file, $line, $sub, ...) = caller(0);
my @info = caller(1);                  # caller's caller

See Also

die, warn, caller