The English module is designed to make your scripts more readable. It creates aliases for all of the special variables that were discussed in a previous chapter.
The following aliases that are defined in Table 15.1
Special Variable
Alias
Miscellaneous
$_
$ARG
@_
@ARG
$"
$LIST_SEPARATOR
$;
$SUBSCRIPT_SEPARATOR or $SUBSEP
Regular Expression or Matching
$&
$MATCH
$`
$PREMATCH
$'
$POSTMATCH
$+
$LAST_PAREN_MATCH
Input
$.
$INPUT_LINE_NUMBER or $NR
$/
$INPUT_RECORD_SEPARATOR or $RS
Output
$|
$OUTPUT_AUTOFLUSH
$,
$OUTPUT_FIELD_SEPARATOR or $OFS
$\
$OUTPUT_RECORD_SEPARATOR or $ORS
Formats
$%
$FORMAT_PAGE_NUMBER
$=
$FORMAT_LINES_PER_PAGE
$_
$FORMAT_LINES_LEFT
$~
$FORMAT_NAME
$^
$FORMAT_TOP_NAME
$:
$FORMAT_LINE_BREAK_CHARACTERS
$^L
$FORMAT_FORMFEED
Error Status
$?
$CHILD_ERROR
$!
$OS_ERROR or $ERRNO
$@
$EVAL_ERROR
Process Information
$$
$PROCESS_ID or $PID
$<
$REAL_USER_ID or $UID
$>
$EFFECTIVE_USER_ID or $EUID
$(
$REAL_GROUP_ID or $GID
$)
$EFFECTIVE_GROUP_ID or $EGID
$0
$PROGRAM_NAME
Internal Variables
$]
$PERL_VERSION
$^A
$AccUMULATOR
$^D
$DEBUGGING
$^F
$SYSTEM_FD_MAX
$^I
$INPLACE_EDIT
$^P
$PERLDB
$^T
$BASETIME
$^W
$WARNING
$^X
$EXECUTABLE_NAME
Below is a program that uses one of the English variables to access information about a matched string. The program:
The Perl code is as follows english.pl:
use English; use strict; my($searchSpace) = "TTTT BBBABBB DDDD"; my($pattern) = "B+AB+"; $searchSpace =~ m/$pattern/; print("Search space: $searchSpace\n"); print("Pattern: /$pattern/\n"); print("Matched String: $English::MATCH\n"); # the English variable print("Matched String: $&\n"); # the standard Perl variable
This program displays:
Search space: TTTT BBBABBB DDDD Pattern: /B+AB+/ Matched String: BBBABBB Matched String: BBBABBB
You can see that the $& and $MATCH variables are equivalent. This means that you can use another programmer's functions without renaming their variables and still use the English names in your own functions.