PERL caller Function

Syntax

caller EXPR
caller

Definition and Usage

Returns information about the current subroutines caller. In a scalar context, returns the caller's package name or the package name of the caller EXPR steps up.
In a list context, with no arguments specified, caller returns the package name, file name and line within the file for the caller of the current subroutine
If EXPR is specified, caller returns extended information for the caller EXPR steps up. That is, when called with an argument of 1, it returns the information for the caller (parent) of the current subroutine, with 2 the caller of the caller (grandparent) of the current subroutine, and so on

Return Value

  • undef on failure
  • Basic information when called with no arguments
  • Extended information when called with an argument

Example

Information returned when calling without argument:
($package, $filename, $line) = caller;
Information returned when calling with argument:
($package, $filename, $line, $subroutine,
$hasargs, $wantarray, $evaltext, $is_require) = caller($i);
The $evaltext and $is_require values are only returned when the subroutine being examined is actually the result of an eval( ) statement.

No comments:

Post a Comment