Special Variables
|
Names
|
$_
|
$ARG
|
@_
|
@ARG
|
$"
|
$LIST_SEPARATOR
|
$;
|
$SUBSCRIPT_SEPARATOR
or $SUBSEP
|
$&
|
$MATCH
|
$`
|
$PREMATCH
|
$'
|
$POSTMATCH
|
$+
|
$LAST_PAREN_MATCH
|
$.
|
$INPUT_LINE_NUMBER
or $NR
|
$/
|
$INPUT_RECORD_SEPARATOR
or $RS
|
$|
|
$OUTPUT_AUTOFLUSH
|
$,
|
$OUTPUT_FIELD_SEPARATOR
or $OFS
|
$\
|
$OUTPUT_RECORD_SEPARATOR
or $ORS
|
$%
|
$FORMAT_PAGE_NUMBER
|
$=
|
$FORMAT_LINES_PER_PAGE
|
$_
|
$FORMAT_LINES_LEFT
|
$~
|
$FORMAT_NAME
|
$^
|
$FORMAT_TOP_NAME
|
$:
|
$FORMAT_LINE_BREAK_CHARACTERS
|
$^L
|
$FORMAT_FORMFEED
|
$?
|
$CHILD_ERROR
|
$!
|
$OS_ERROR or $ERRNO
|
$@
|
$EVAL_ERROR
|
$$
|
$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
|
$]
|
$PERL_VERSION
|
$^A
|
$ACCUMULATOR
|
$^D
|
$DEBUGGING
|
$^F
|
$SYSTEM_FD_MAX
|
$^I
|
$INPLACE_EDIT
|
$^P
|
$PERLDB
|
$^T
|
$BASETIME
|
$^W
|
$WARNING
|
$^X
|
$EXECUTABLE_NAME
|
Variable
|
Description
|
$_$ARG
|
This
is the default variable which stores the current values.
|
$0
or $PROGRAM_NAME
|
Stores
the file name of the Perl script.
|
$/
|
The
input record separator, this has a default value of ‘n’ which is newline
character
|
$.
|
Holds
the current line number of the file that is being read
|
$,
|
Output
field separator, this is mainly used by print() statement. By default value
of this is set to 0, we can change the value of this variable.
|
$
|
Output
record separator, the value of this variable will be empty; we can assign any
value to this, which will be used by print() statement while printing the
output.
|
$#
|
This
variable is used for output format while printing numbers.
|
$%$FORMAT_PAGE_NUMBER
|
Will
hold the current page number of the file read.
|
$=$FORMAT_LINES_PER_PAGE
|
Will
Hold the current page length of the file read.
|
$-$FORMAT_LINES_LEFT
|
Holds
the value of the number of lines left to print from the page.
|
$~$FORMAT_NAME
|
Format
Name: Holds the format of the currently selected output by default the file
handle name.
|
$^$FORMAT_TOP_NAME
|
Holds
the value of the heading format of the file handler, by default value will be
_TOP followed by file handle name.
|
$|$OUTPUT_AUTOFLUSH
|
Default
is zero; this is used to flush the output buffer after every write() or
print().
|
$$
|
Will
hold the running process number of Perl interpreter.
|
$?
|
Status
code : Pipe and system call. Return status of the command executed.
|
$&$MATCH
|
Used
in regular expressions, this will hold a string of the last successful
pattern match.
|
$`$PREMATCH
|
Used
in regular expressions, this will hold string preceded by last successful
pattern match.
|
$’$POSTMATCH
|
Used
in regular expressions, this will hold a string that followed by the last
successful pattern match.
|
$+$LAST_PAREN_MATCH
|
Holds
the string of the last bracket that is matched by the last pattern search.
|
$<digit>
|
$1,
$2, $3 …. Holds the values of the pattern matched in order.
|
$[
|
First
index: Array, substring.
|
$]
|
Version
of Perl.
|
$”
|
Separator
used for list elements, by default value is a white space.
|
$;
|
Subscript
separator used in multi-dimensional arrays
|
$!
|
In
numeric context, prints the error number. In string context, print the error.
|
$@
|
Will
hold the syntax error info, used when eval() is used.
|
$<
|
Holds
the real UID (user id) of the process running the script.
|
$>
|
Holds
the effective UID of the process running the script.
|
$(
|
Holds
the real GID (group id) of the process running the script.
|
$)
|
Holds
the effective GID of the process running the script.
|
$^D$DEBUGGING
|
Holds
the current value of the debugging flags.
|
$^C
|
Holds
the current value of the flag when –c command line switch is used.
|
$^F
|
Maximum
system file descriptor, by default value is set to 2
|
$^I$INPLACE_EDIT
|
Holds
the value of –i command line switch.
|
$^M
|
Special
Memory pool, can be used when Perl script dies with out-off memory error.
|
$^O$OSNAME
|
Operating
system info is stored. ‘Linux’ for Linux systems, ‘mswin32′ for Windows
systems.
|
$^T$BASETIME
|
The
time when the scripts running in seconds.
|
$^W$WARNING
|
The
current value of the –w command line switch. Warning switch.
|
$ARGV
|
Name
of the current file, when <> is used.
|
Array Special Variables:
Variable
|
Description
|
@INC
|
Holds
a list of paths, where Perl library modules or scripts can be looked into
while executing the current script. This @INC is used by use and require
statements to look into those paths for library modules.
|
@ARGV
|
Stores
the command line arguments passed.
|
@_
|
Used
in subroutines, while passing the parameters to the subroutines.
|
@F
|
This
is the array into which the input lines are stored when auto split –a
(command line switch is used).
|
Hash Special Variables:
Variable
|
Description
|
%INC
|
File
name will be the keys; values will be the path to those files. Used by do,
use and require.
|
%ENV
|
System
environmental variables.
|
%SIG
|
Signals
handler.
|
Comments
Post a Comment