Special Variables: $variable - Name
Special Variables: $variable - Name
A variable in Perl is evaluated at runtime to derive a value that is one of the following: a string, a
number, or a pointer to scalar. (To see the use of pointers and references, refer to Chapter 3,
"References.")
To print out the value of a variable, you use a print statement. Therefore, to print the value of
$name, you would make the following call:
print$name;
The value of $name is printed to the screen. Perl scripts "expect" input from a standard input (the
keyboard) and to write to the standard output. Of course, you can also use the print statement to
print the values of special variables that are built into Perl.
Special Variables
Table 2.1 lists the special variables in Perl. The first column contains the variable, and the second
contains a verbose name that you can use to make the code readable. The third column in the
table describes the contents of each variable.
You can use the verbose names (in column 2) by including the following line in the beginning of
your code:
useEnglish;
This statement will let you use the English.pm module in your code. (I cover the use of modules
in Chapter 4, "Introduction to Perl Modules.") Not all Perl variables have an equivalent name in
the English.pm module. The entry "n/a" in the second column indicates that there is not an
English name for the variable.
Table 2.1. Special variables in Perl.
Variable
English Name
Description
$_
$ARG
$1$9
n/a
$&
$MATch
$`
$PREMATch
$POSTMATch
$+
$LAST_PAREN_MATch
$*
$MULTILINE_MATchING
$.
$INPUT_LINE_NUMBER
$/
$INPUT_RECORD_SEPARATOR
$|
$AUTO_FLUSH
$,
$OUTPUT_FIELD_SEPARATOR
$\
$INPUT_RECORD_SEPARATOR
$"
$LIST_SEPARATOR
$;
$SUBSCRIPT_SEPARATOR
emulation
$#
$FORMAT
$%
$FORMAT_PAGE_NUMBER
$=
$FORMAT_LINES_PER_PAGE
$FORMAT_LINES_LEFT
$~
$FORMAT_NAME
$^
$FORMAT_TOP_NAME
$:
$FORMAT_LINE_BREAK_chARACTERS