Wednesday 4 November 2009

Special Variables

The following variables are global and should be localized in subroutines:

$_ The default input and pattern-searching space.
$. The current input line number of the last filehandle that was read. Reset only
when the filehandle is closed explicitly.

$/ The input record separator, newline by default. May be multi-character.
$, The output field separator for the print operator.
$" The separator which joins elements of arrays interpolated in strings.
$\ The output record separator for the print operator.
$# The output format for printed numbers. Deprecated.
$* Set to 1 to do multilinematching within strings.
$? The status returned by the last ‘. . .‘ command, pipe close or system operator.
$] The Perl version number, e.g. 5.004.
$[ The index of the first element in an array, and of the first character in a substring. Default is 0. Deprecated.
$; The subscript separator for multi-dimensional array emulation. Default is "\034".
$! If used in a numeric context, yields the current value of errno. If used in a
string context, yields the corresponding error string.
$@ The Perl error message from the last eval or do EXPR command.
$: The set of characters after which a string may be broken to fill continuation fields (starting with ‘ˆ’) in a format.
$0 The name of the file containing the Perl script being executed. May be assigned to.
$$ The process ID of the Perl interpreter running this script. Altered (in the child process) by fork.
$> The real user ID of this process.
$> The effective user ID of this process.
$( The real group ID of this process.
$) The effective group ID and groups of this process.

The following variables are context dependent and need not be localized:

$% The current page number of the currently selected output channel.
$= The page length of the current output channel. Default is 60 lines.
$- The number of lines remaining on the page.
$| If set to nonzero, forces a flush after every write or print on the output
channel currently selected. Default is 0.
$ARGV The name of the current file when reading from <> .


The following variables are always local to the current block:

$& The string matched by the last successful pattern match.
$‘ The string preceding what was matched by the last successful match.
$’ The string following what was matched by the last successful match.
$+ The last bracket matched by the last search pattern.
$1. . .$9. . . Contain the subpatterns from the corresponding sets of parentheses in the last pattern successfully matched. $10 and up are only available if the match contained that many subpatterns.

For further study : perldoc perlvar

No comments:

Post a Comment

Tweets by @sriramperumalla