Perl special variables
December 04, 2009 04:33:05 Last update: December 04, 2009 04:33:05
| Variable | Meaning |
|---|---|
| $_ | The default or implicit variable. |
| @_ | Within a subroutine the array @_ contains the parameters passed to that subroutine. |
| $a, $b | Special package variables when using sort() |
| $<digit> | Contains the subpattern from the corresponding set of capturing parentheses from the last pattern match, not counting patterns matched in nested blocks that have been exited already. |
| $. | Current line number for the last filehandle accessed. |
| $/ | The input record separator, newline by default. |
| $| | If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). |
| $, | The output field separator for the print operator. If defined, this value is printed between each of print's arguments. Default is undef. |
| $\ | The output record separator for the print operator. If defined, this value is printed after the last of print's arguments. Default is undef. |
| $? | The status returned by the last pipe close, backtick (`` ) command, successful call to wait() or waitpid(), or from the system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up to look like it). Thus, the exit value of the subprocess is really ($?>> 8 ) |
| $! | If used numerically, yields the current value of the C errno variable, or in other words, if a system or library call fails, it sets this variable. This means that the value of $! is meaningful only immediately after a failure.
If used as a string, yields the corresponding system error string. |
| $@ | The Perl syntax error message from the last eval() operator. If $@ is the null string, the last eval() parsed and executed correctly. (Mnemonic: Where was the syntax error "at"?) |
| $$ | The process number of the Perl running this script. |
| $0 | Contains the name of the program being executed. |
| ARGV | The special filehandle that iterates over command-line filenames in @ARGV . Usually written as the null filehandle in the angle operator <>. |
| $ARGV | contains the name of the current file when reading from <>. |
| @ARGV | The array @ARGV contains the command-line arguments intended for the script. |
| @INC | The array @INC contains the list of places that the do EXPR , require, or use constructs look for their library files. It initially consists of the arguments to any -I command-line switches, followed by the default Perl library, probably /usr/local/lib/perl, followed by ".", to represent the current directory. |
| %INC | The hash %INC contains entries for each filename included via the do, require, or use operators. The key is the filename you specified (with module names converted to pathnames), and the value is the location of the file found. |
| %ENV | The hash %ENV contains your current environment. Setting a value in ENV changes the environment for any child processes you subsequently fork() off. |
The full list is available from Perldoc.
Easy email testing with http://www.ximailstop.com