home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book Home Programming PerlSearch this book

Chapter 28. Special Names

This chapter is about variables that have special meanings to Perl. Most of the punctuational names have reasonable mnemonics, or analogs in one of the shells (or both). But if you want to use long variable names as synonyms, just say:

use English;
at the top of your program. This aliases all the short names to long names in the current package. Some of these variables even have medium names, generally borrowed from awk. Most people eventually settle on using the short names, at least for the more commonly used variables. Throughout this book, we consistently refer to the short names, but also often mention the long names (in parentheses) so that you can look them up easily in this chapter.

The semantics of these variables can be quite magical. (To create your own magic, see Chapter 14, "Tied Variables".) A few of these variables are read-only. If you try to assign values to them, an exception will be raised.

In what follows, we'll first provide a concise listing of the variables and functions for which Perl assigns a special meaning, grouped by type, so you can look up variables that you're not sure of the proper name. Then we'll explain all of the variables alphabetically under their proper name (or their least improper name).

28.1. Special Names Grouped by Type

We used the word "type" loosely--the sections here actually group variables more by their scope, that is, where they're visible from.

28.1.1. Regular Expression Special Variables

The following special variables related to pattern matching are visible throughout the dynamic scope in which the pattern match occurred (except for $*, which is deprecated). In other words, they behave as though they were declared with local, so you needn't declare them that way yourself. See Chapter 5, "Pattern Matching".

$*
$digits
@+ (@LAST_MATCH_END)
@- (@LAST_MATCH_START)
$+ ($LAST_PAREN_MATCH)
$^R ($LAST_REGEXP_CODE_RESULT)
$& ($MATCH)
$' ($POSTMATCH)
$` ($PREMATCH)

28.1.2. Per-Filehandle Variables

These special variables never need to be mentioned in a local because they always refer to some value pertaining to the currently selected output filehandle--each filehandle keeps its own set of values. When you select another filehandle, the old filehandle remembers the values it had for these variables, and the variables now reflect the values of the new filehandle. See also the FileHandle module in Chapter 32, "Standard Modules".

$| ($AUTOFLUSH, $OUTPUT_AUTOFLUSH)
$- ($FORMAT_LINES_LEFT)
$= ($FORMAT_LINES_PER_PAGE)
$~ ($FORMAT_NAME)
$% ($FORMAT_PAGE_NUMBER)
$^ ($FORMAT_TOP_NAME)

28.1.3. Per-Package Special Variables

These special variables exist separately in each package. There should be no need to localize them, since sort automatically does so on $a and $b, and the rest are probably best left alone (though you will need to declare them with our if you use strict).

$a
$b
@EXPORT
@EXPORT_OK
%EXPORT_TAGS
%FIELDS
@ISA

%OVERLOAD
$VERSION

28.1.4. Program-wide Special Variables

These variables are truly global in the fullest sense--they mean the same thing in every package, because they're all forced into package main when unqualified (except for @F, which is special in main, but not forced). If you want a temporary copy of one of these, you must localize it in the current dynamic scope.

%ENV
%INC
%SIG
%!
%^H

@_
@ARGV
@F
@INC

$_ ($ARG)
$0 ($PROGRAM_NAME)
$ARGV

$! ($ERRNO, $OS_ERROR)
$" ($LIST_SEPARATOR)
$#
$$ ($PID, $PROCESS_ID)
$( ($GID, $REAL_GROUP_ID)
$) ($EGID, $EFFECTIVE_GROUP_ID)
$, ($OFS, $OUTPUT_FIELD_SEPARATOR)
$. ($NR, $INPUT_LINE_NUMBER)
$/ ($RS, $INPUT_RECORD_SEPARATOR)
$: ($FORMAT_LINE_BREAK_CHARACTERS)
$; ($SUBSEP, $SUBSCRIPT_SEPARATOR)

$< ($UID, $REAL_USER_ID)
$> ($EUID, $EFFECTIVE_USER_ID)
$? ($CHILD_ERROR)
$@ ($EVAL_ERROR)
$[
$\ ($ORS, $OUTPUT_RECORD_SEPARATOR)
$]  ($OLD_PERL_VERSION)
$^A ($ACCUMULATOR)
$^C ($COMPILING)
$^D ($DEBUGGING)
$^E ($EXTENDED_OS_ERROR)
$^F ($SYSTEM_FD_MAX)
$^H
$^I ($INPLACE_EDIT)
$^L ($FORMAT_FORMFEED)
$^M
$^O ($OSNAME)
$^P ($PERLDB)
$^R ($LAST_REGEXP_CODE_RESULT)
$^S (EXCEPTIONS_BEING_CAUGHT)
$^T ($BASETIME)
$^V ($PERL_VERSION)
$^W ($WARNING)
${^WARNING_BITS}
${^WIDE_SYSTEM_CALLS}
$^X ($EXECUTABLE_NAME)

28.1.5. Per-Package Special Filehandles

Except for DATA, which is always per-package, the following filehandles are always assumed to be in main when not fully qualified with another package name:

_ (underline)
ARGV
ARGVOUT
DATA
STDIN
STDOUT
STDERR

28.1.6. Per-Package Special Functions

The following subroutine names have a special meaning to Perl. They're always called implicitly because of some event, such as accessing a tied variable or trying to call an undefined function. We don't describe them in this chapter since they all receive heavy-duty coverage elsewhere in the book.

Undefined function call interceptor (see Chapter 10, "Packages"):

AUTOLOAD

Moribund objects' finalization (see Chapter 12, "Objects"):

DESTROY

Exception objects (see die in the next chapter):

PROPAGATE

Auto-init and auto-cleanup functions (see Chapter 18, "Compiling"):

BEGIN, CHECK, INIT, END

Tie methods (see Chapter 14, "Tied Variables"):

BINMODE, CLEAR, CLOSE, DELETE, EOF, EXISTS, EXTEND, FETCH, FETCHSIZE,
FILENO, FIRSTKEY, GETC, NEXTKEY, OPEN, POP, PRINT, PRINTF, PUSH, READ,
READLINE, SEEK, SHIFT, SPLICE, STORE, STORESIZE, TELL, TIEARRAY,
TIEHANDLE, TIEHASH, TIESCALAR, UNSHIFT, WRITE


Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.