Chapter 36. Special Variables

The alternative names for special variables are provided by the standard module English.

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

$_

Alternative: $ARG.

The default input, output, and pattern-searching space.

$.

Alternatives: $INPUT_LINE_NUMBER, $NR.

The current input line number of the last filehandle that was read. Reset only when the filehandle is closed explicitly.

$/

Alternatives: $INPUT_RECORD_SEPARATOR, $RS.

The string that separates input records. Default value is a newline.

$,

Alternatives: $OUTPUT_FIELD_SEPARATOR, $OFS.

The output field separator for the print functions. Default value is an empty string.

$"

Alternative: $LIST_SEPARATOR.

The separator that joins elements of arrays interpolated in strings. Default value is a single space.

$

Alternatives: $OUTPUT_RECORD_SEPARATOR, $ORS.

The output record separator for the print functions. Default value is an empty string.

$#

The output format for printed numbers. Deprecated. Use printf instead.

$*

Set to 1 to do multiline matching within strings. Deprecated; see the m and s modifiers.

$?

Alternative: $CHILD_ERROR.

The status returned by the last ` . . . ` command, pipe close, wait, waitpid, or system function.

$]

The Perl version number, e.g., 5.006. See also $^V.

$[

The index of the first element in an array or list, and of the first character in a substring. Default is zero. Deprecated. Do not use.

$;

Alternatives: $SUBSCRIPT_SEPARATOR, $SUBSEP.

The subscript separator for multidimensional hash emulation. Default is "34".

$!

Alternatives: $OS_ERROR, $ERRNO.

If used in numeric context, yields the current value of errno. Otherwise, yields the corresponding error string.

$@

Alternative: $EVAL_ERROR.

The Perl error message from the last eval or do expr command.

$:

Alternative: $FORMAT_LINE_BREAK_CHARACTERS.

The set of characters after which a string may be broken to fill continuation fields (starting with ^) in a format.

$0

Alternative: $PROGRAM_NAME.

The name of the file containing the Perl script being executed. May be assigned to.

$$

Alternatives: $PROCESS_ID, $PID.

The process id of the Perl interpreter running this script. Altered (in the child process) by fork.

$<

Alternatives: $REAL_USER_ID, $UID.

The real user id of this process.

$>

Alternatives: $EFFECTIVE_USER_ID, $EUID.

The effective user id of this process.

$(

Alternatives: $REAL_GROUP_ID, $GID.

The real group id of this process.

$)

Alternatives: $EFFECTIVE_GROUP_ID, $EGID.

The effective group id, or a space-separated list of group ids, of this process.

$^A

Alternative: $ACCUMULATOR.

The accumulator for formline and write operations.

$^C

Alternative: $COMPILING.

True if Perl is run in compile-only mode using command-line option -c.

$^D

Alternative: $DEBUGGING.

The debug flags as passed to Perl using command-line option -D.

$^E

Alternative: $EXTENDED_OS_ERR0R.

Operating-system dependent error information.

$^F

Alternative: $SYSTEM_FD_MAX.

The highest system file descriptor, ordinarily 2.

$^H

The current state of syntax checks.

$^I

Alternative: $INPLACE_EDIT.

In-place edit extension as specified using command-line option -i.

$^L

Alternative: $FORMAT_FORMFEED.

Formfeed character used in formats.

$^M

Emergency memory pool.

$^O

Alternative: $OSNAME.

Operating system name.

$^P

Alternative: $PERLDB.

Internal debugging flag.

$^S

Alternative: $EXCEPTIONS_BEING_CAUGHT.

Current state of the Perl interpreter.

$^T

Alternative: $BASETIME.

The time (as delivered by time) when the program started. This value is used by the file test operators -M, -A, and -C.

$^{TAINT}

The current state of taint mode.

$^V

Alternative: $PERL_VERSION.

The Perl version as a v-string, e.g., 5.6.0. Use %vd format to print it.

$^W

Alternative: $WARNING.

The value of the -w option as passed to Perl.

$^X

Alternative: $EXECUTABLE_NAME.

The name by which Perl was invoked.

$AUTOLOAD

The name of the undefined subroutine that was called.

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

$%

Alternative: $FORMAT_PAGE_NUMBER.

The current page number of the currently selected output handle.

$=

Alternative: $FORMAT_LINES_PER_PAGE.

The page length of the current output handle. Default is 60 lines.

$-

Alternative: $FORMAT_LINES_LEFT.

The number of lines remaining on the page.

$~

Alternative: $FORMAT_NAME.

The name of the current report format.

$^

Alternative: $FORMAT_TOP_NAME.

The name of the current top-of-page format.

$|

Alternative: $OUTPUT_AUTOFLUSH.

If set to nonzero, forces a flush after every write or print on the currently selected output handle. Default is zero.

$ARGV

The name of the current file when reading from < >.

The following variables are always local to the current block:

$&

Alternative: $MATCH.

The string matched by the last successful pattern match.

$`

Alternative: $PREMATCH.

The string preceding what was matched by the last successful match.

$'

Alternative: $POSTMATCH.

The string following what was matched by the last successful match.

$+

Alternative: $LAST_PAREN_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.

$^N

Alternative: $LAST_SUBMATCH_RESULT.

The text matched by the most recently closed group.

$^R

Alternative: $LAST_REGEXP_CODE_RESULT.

Result of last (?{ code }).

perlvar.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset