Previous Page Next Page

A.2. Special Variables

Table A.2. Filehandles
VariableWhat It Does
$|If nonzero, forces buffer flush after every write and print on the currently selected filehandle
$%Current page number of currently selected filehandle
$=Current page length of currently selected filehandle
$–Number of lines left on the page for currently selected filehandle
$~Name of current report format for currently selected filehandle
$^Name of current top-of-page format for currently selected filehandle


Table A.3. Local to Block
VariableWhat It Does
$1.. $9Contains remembered subpatterns that reference a corresponding set of parentheses (same as \1..\9)
$ &The string matched by the last pattern match (like sed editor)
$'The string preceding what was matched in the last pattern match
$'The string that follows whatever was matched by the last pattern match
$+The last pattern matched by the last search pattern


Example A.1.

$str="old and restless";

print "$&\n" if $str =~ /and/;
print "$'\n" if $str =~ /and/;
print "$'\n" if $str =~ /and/;
print "\nold string is: $str\n";
$str=~s/(old) and (restless)/$2 and $1/;
print "new string is: $str\n";
print "\nlast pattern matched: $+\n";

(Output)
and
old
restless
old string is: old and restless
new string is: restless and old
last pattern matched is: restless

Table A.4. Global
VariableWhat It Does
$_Default input and pattern-searching space.
$.Current input line number of last filehandle that was read; must close the filehandle to reset line numbers for next filehandle.
$/Input record separator, newline by default. (Like RS in awk.)
$\Output record separator for the print function. Does not print a newline unless set: $\="\n"
$,Output field separator for the print function. Normally delimiter is not printed between comma-separated strings unless set: S,=" ".
$"Same as $ but applies to printing arrays when in double quotes. Default is space.
$#Output format for numbers printed with the print function. (Like OMFT in awk.)
$$The process ID number of the Perl program running this script.
$?Status returned by last pipe closed, command in backquotes, or system function.
$*Default is 0. If set to 1, does a multiline match within a string; 0 for a match within a single line.
$0Name of this Perl script.
$[Index of first element of an array, and first character in a substring. Default is 0.
$]The first part of the string is printed out when using perl -v for version information.
$;The subscript separator for multidimensional array emulation. Default is \034. (Like SUBSEP in awk.)
$!Yields the current value of errno (system error number) if numeric, and the corresponding system error string.
$@Error message from the last eval, do, or require function.
$<The real uid of this process.
$>The effective uid of this process.
$(The real gid of this process.
$)The effective gid of this process.
$:The set of characters after which a string may be broken to fill continuation lines (starting with ^) in a format. Default is \n- to break on whitespace, newline, or colon.
$^AThe accumulator for formline and write operations.
$^CTRUE if Perl is run in compile-only mode using command-line option -c.
$^DPerl's debug flags when -D switch is used.
$^EOperating-system-dependent error information.
$^FMaximum file descriptor passed to subprocess, usually 2.
$^HThe current state of syntax checks.
$^ICurrent value of inplace-edit extension when -i switch is used. Use undef to disable inplace editing.
$^LForm feed character used in formats.
$^MEmergency memory pool.
$^OName of the operating system.
$^PInternal Perl debugging flag.
$^SState of the Perl interpreter.
$^TTime of day when script started execution. Used by -A, -C, and -M test operators and can be set to any number value returned by time to perform file tests relative to the current time.
$^VThe Perl version.
$^WThe current value of the warning switch.
$^XThe full pathname by which this Perl was invoked.
_An underscore. The special designator for file testing when stating files.
ARGVThe special filehandle array for looping over line arguments.
$ARGVThe variable containing the name of the current file when reading from <ARGV>.
@ARGVThe array containing command-line arguments.
DATASpecial filehandle referring to anything following _ _END_ _.
@FThe array into which input lines are autosplit when the -a switch is used.
@INCArray containing pathnames where require and do functions look for files that are to be included in this script.
%INCAssociative array containing entries for files that have been included by calling do or require. The key is the filename and the value is its location.
%ENVAssociative array containing the current environment.
@EXPORTDefault symbols to be exported.
@EXPORT_OKSymbols to be exported upon request by the user.
%EXPORT_TAGSUsed by Exporter.pm to collectively name sets of symbols.
%SIGAssociative array used to set signal handlers.
STDERRSpecial filehandle for standard error.
STDINSpecial filehandle for standard input.
STDOUTSpecial filehandle for standard output.


 

Previous Page Next Page