|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303
|
|
Chapter 21:
|
|
|
|
Special Variables
|
|
Computer languages follow the extended Sapir-Whorf hypothesis,
which states that because the Eskimos had 900 words for snow,
they decided to move north.
|
|
- Dave Griffith
|
|
Perl has several dozen built-in "special" variables. Most of these are sel-
dom used and thus impossible to remember. Complicating the situation fur-
ther, these variables may have long ($INPUT_LINE_NUMBER), medium
($NR), or short ($.) names.1
|
|
Although the short names are quick to type, they have virtually no mne-
monic value (What is $., anyway?). Worse, because they aren't alphabeti-
cal, they are difficult to look up in a printed index. So, we recommend that
you use the medium or long names unless this begins to seem verytedious.
|
|
Perl supports the short (non-alphabetic) names by default. To use the Eng-
lish (i.e., medium or long) names, include this command at the start of your
Perl script:
|
|
use English;
|
|
Note: Due to an implementation problem, use of the English.pm
module causes Perl to act as if a "MATCH" variable has been used,
|
|
|
|
1The medium length names are borrowed, in general,from C and awk usage
under the Unix operating system. Many of the short names are borrowed
from sh, the Unix "Bourne shell".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
slowing down any use of regular expressions in the script. Sigh. So, if
you need the last bit of speed from your scripts, you may wish to avoid
use of this module (until the bug is fixed :-).
|
|
Each entry begins with the applicable names, followed by a a summary of
the variable's scope (e.g., global), access limitations (r-o or r/w), default
value, and a short description. If the scope is given as global, you will need
to localize the variable with my()or local()if you want to work with a
more private copy in the current code block.
|
|
The access limitation designation, "r-o" (read-only) or r/w (read/write), is
more prescriptive than descriptive: you may be able to write to a read-only
variable, but we make no guarantees as to the results (nor do we recommend
that you try it!).
|
|
Data Structures
|
|
These variables allow programs to affect the default behavior of certain
operations related to data structures.
|
|
$LIST_SEPARATOR(none)$"
global, r/w, " "- character used to separate list elements when
interpolated into a double-quoted string
|
|
$SUBSCRIPT_SEPARATOR$SUBSEP$;
global, r/w, "\034"- character used to separate subscripts in (old)
multi-dimensional array emulation
|
|
Format
|
|
Formats are a tool for creating printed reports, often in a page-oriented
manner. The "output channel specific" variables below are relevant to
specific filehandles. Thus, you must selectthe appropriate filehandle
before you can use any of them.
|
|
With the exception of $ACCUMULATOR, all of the variables in this section
can be set by a method whose name is the lower-case version of the variable
name. For instance, these three commands are equivalent:
|
|
$FORMAT_FORMFEED = "\f";
|
|
format_formfeed HANDLE "\f";
|
|
HANDLE->format_formfeed("\f");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Formats are very useful for some tasks, but are excessively complicated for
most output formatting jobs. Unless you need top-of-form processing or other
format-specific features, consider using printor printf.
|
|
$ACCUMULATOR(none)
global, r-o, none - current value of the write accumulator
|
$^A
|
|
$FORMAT_FORMFEED(none)
global, r/w, "\f"- string to be output to force a formfeed
|
$^L
|
|
$FORMAT_LINE_BREAK_CHARACTERS(none)$:
global, r/w, " \n-"- set of characters after which the line may be
broken
|
|
$FORMAT_LINES_LEFT(none)$-
output channel specific, r-o, none - number of printable lines left in
the output page
|
|
$FORMAT_LINES_PER_PAGE(none)$=
output channel specific, r/w, 60 - number of printable lines in the
output page
|
|
$FORMAT_NAME(none)$~
output channel specific, r-o, none - name of the current format
|
|
$FORMAT_PAGE_NUMBER(none)$%
output channel specific, r-o, none - number of the current output page
|
|
$FORMAT_TOP_NAME(none)$^
output channel specific, r-o, none - name of the current top-of-form
format
|
|
Input/Output
|
|
(none)ARGV(none)
global, r-o, none - filehandle that successively refers to files named
in the command line (<>is shorthand for <ARGV>)
|
|
(none)DATA(none)
global, r-o, system-dependent - filehandle for data encapsulated in
a script file
|
|
(none)STDERR(none)
global, r-o, system-dependent - filehandle for the "standard error"
(output) stream
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(none)STDIN(none)
global, r-o, system-dependent - filehandle for the "standard input"
stream
|
|
(none)STDOUT(none)
global, r-o, system-dependent - filehandle for the "standard
output" stream
|
|
(none)(none)_
global, r-o, system-dependent - filehandle for data retrieved by a
file, lstat, or testcall
|
|
(none)@F(none)
global within main, r-o, none - fields from the last input line, if
autosplit (-a) mode is on
|
|
(none)$ARG$_
global, r/w, none - default unspecified variable; used for I/O,
pattern-matching, and miscellaneous other operations
|
|
(none)$ARGV(none)
global, r-o, none - name of the file being read by <ARGV>or <>
|
|
$INPLACE_EDIT(none)$^I
global, r-o, undefined - extension (if any) used for backup copies of
files that are being edited "inplace" (see the -icommand line
flag); may be unsetto disable inplace editing
|
|
$INPUT_LINE_NUMBER$NR
global, r-o, none - number of the current input line
|
$.
|
|
$INPUT_RECORD_SEPARATOR$RS$/
global, r/w, "\n"- character used to separate input records
|
|
$LIST_SEPARATOR(none)$"
global, r/w, " "- character used to separate list elements when
interpolated into a double-quoted string
|
|
(none)$OFMT$#
global, r/w, "%.14g"(approximately) - controls the format used
by printin formatting numeric values; deprecated, use printf
instead
|
|
$OUTPUT_AUTOFLUSH
|
(none)
|
$|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output channel specific, r/w, 0- if non-zero, forces output to be
"unbuffered" (written immediately)
|
|
$OUTPUT_FIELD_SEPARATOR$OFS$,
global, r/w, ""- character used by printto separate fields
|
|
$OUTPUT_RECORD_SEPARATOR$ORS$\
global, r/w, ""- character used by printto separate records
|
|
Operating Environment
|
|
These variables allow a Perl script to research (and occasionally modify)
the environment under which it is running.
|
|
(none)@ARGV
global, r-o, none - the script's command-line arguments
|
(none)
|
|
(none)@INC(none)
global, r-o, none - names of files that have been included (e.g., by
door require)
|
|
(none)%INC(none)
global, r-o, none - path information ("requested file" -> "full path
name") for files that have been included (e.g., by door require)
|
|
(none)%ENV(none)
global, r-o, none - environment variables ("name" -> "value")
|
|
(none)%SIG(none)
global, r/w, none - used to set signal handlers ("signal name" ->
"handler name")
|
|
$BASETIME(none)$^T
global, r-o, none - starting time for the script's execution (in seconds
since the "epoch"); note that the Mac and Unix epochs differ!
|
|
$EXECUTABLE_NAME(none)
global, r-o, none - name of the Perl interpreter, as invoked
|
$^X
|
|
$EXTENDED_OS_ERROR(none)$^E
global, r-o, none - (possibly) more descriptive error information
than $ERRNO; used for information on Toolbox modules
|
|
$OS_ERROR
|
$ERRNO
|
$!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global, r-o, none - value of the system errnovariable (if evaluated
numerically) or the corresponding system error message (if evaluat-
ed as a string)
|
|
$OSNAME(none)$^O
global, r-o, none - intended operating system for this port of the
Perl interpreter
|
|
$PROGRAM_NAME(none)$0
global, r-o, none - name of the file containing the current Perl script
|
|
Package Management
|
|
These variables are used to support Perl's "package" facility.
|
|
@EXPORT(none)(none)
lexical, r/w, none - names of symbols that are exported by default
from this package (try to use $EXPORT_OK, instead!)
|
|
@EXPORT_FAIL(none)(none)
lexical, r/w, none - names of symbols that cannot be exported from
this package
|
|
@EXPORT_OK(none)(none)
lexical, r/w, none - names of symbols that are exported upon request
from this package
|
|
%EXPORT_TAGS(none)(none)
lexical, r/w, none - sets of symbols that are exported upon request
from this package
|
|
@ISA(none)
lexical, r/w, empty - names of this package's base classes
|
(none)
|
|
%OVERLOAD(none)(none)
lexical, r/w, none - (was) used to overload a package's operators;
now subsumed by the overloadpragma
|
|
Perl Interpreter
|
|
These variables reflect (and occasionally control) the operation of the Perl
interpreter. Naive programmers beware!
|
|
(none)(none)
global, r/w, 0- index of the first element in an array
|
$[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(none)(none)$^M
global, r/w, none - arcane way to allocate memory in emergencies
|
|
(none)(none)$^H
global, r-o, none - arcane compiler hints related to use of pragmas
|
|
$DEBUGGING(none)$^D
global, r/w, 0- numeric value of the debugging flags (see the -D
command line flag)
|
|
$EVAL_ERROR(none)$@
global, r-o, none - syntax error message from the preceding eval
|
|
$PERL_VERSION(none)
global, r-o, none - version.patchlevel (e.g., 5.00401)
|
$]
|
|
$PERLDB(none)
global, r-o, none - Perl interpreter's internal debugger flag
|
$^P
|
|
$WARNING(none)
global, r-o, 0- value of the warning switch (boolean)
|
$^W
|
|
Process Management
|
|
These variables are, in general, only relevant on systems that support Unix-
style process management. MacPerl does not currently do this.
|
|
$CHILD_ERROR(none)
global, r-o, none - status returned by last sub-process
|
$?
|
|
$EFFECTIVE_GROUP_ID$EGID$)
global, r-o, none - effective group ID (EGID) of the current process
|
|
$EFFECTIVE_USER_ID$EUID$>
global, r-o, none - effective user ID (EUID) of the current process
|
|
$PROCESS_ID$PID
global, r-o, none - process ID (PID) of the current process
|
$$
|
|
$REAL_USER_ID$UID
global, r-o, none - real user ID (UID) of the current process
|
$<
|
|
$REAL_GROUP_ID$GID$(
global, r-o, none - real group ID (GID) of the current process
|
|
$SYSTEM_FD_MAX
|
(none)
|
$^F
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
global, r-o, 2- maximum system file descriptor (largest file
descriptor passed to execed processes)
|
|
Regular Expression
|
|
These (read-only) variables are set by regular expression operations. The
variables $[1-9]are the most generally useful, containing text matched by
the corresponding set of parentheses in the preceding regular expression.
|
|
Each of these variables, except for $*, has a local value in the current
block, i.e., they are dynamically scoped. They do not need to be localized
with local()or my().
|
|
Note: Use of the $MATCH($&), $PREMATCH($`), or $POSTMATCH($`)
variables anywhere in a Perl script will cause perl to save copies of the
input strings to all regular expressions (in case they might be needed
later). This can cause affected scripts to run substantially slower than
they otherwise might! In short, don't use these variables casually.
|
|
(none)(none)
dynamic, r-o, none - text found by this set of parentheses
|
$[1-9]
|
|
$LAST_PAREN_MATCH(none)
dynamic, r-o, none - text found by the last matching set of
parentheses
|
$+
|
|
$MATCH(none)$&
dynamic, r-o, none - text found by the last successful pattern match
|
|
$MULTILINE_MATCHING(none)$*
global, r/w, 0- set to 1 to allow multi-line matching within strings;
deprecated, use /mand/or /s, instead
|
|
$PREMATCH(none)$`
dynamic, r-o, none - string preceding the text found by the last
successful pattern match
|
|
$POSTMATCH(none)$'
dynamic, r-o, none - string following the text found by the last
successful pattern match
|
Copyright © 1997-1998 by Prime Time Freeware. All Rights Reserved.