Perl 5 Built-In Variables : Special Variables « Language Basics « Perl






Perl 5 Built-In Variables

   
 
Variable    English Name                     Description

$_          $ARG                             default input and pattern-searching space

$&          $MATCH                           string matched by the last successful pattern match

$`          $PREMATCH                        string preceding whatever was matched by the last successful pattern

$'          $POSTMATCH                       string following whatever was matched by the last successful pattern

$+          $LAST_PAREN_MATCH                last bracket matched by the last search pattern
 
$*          $MULTILINE_MATCHING              Perl 5 does multi-line matching within a string if it is 1(the default is 0)

$.          $INPUT_LINE_NUMBER               current input line number from the last file handle read

$/          $INPUT_RECORD_SEPARATOR          The input record separator (newline by default)

$|          $OUTPUT_AUTOFLUSH                If it is nonzero, forces a flush after every write or print on the currently selected output device (the default is 0)

$,          $OUTPUT_FIELD_SEPARATOR          field separator for the print function

$\          $OUTPUT_RECORD_SEPARATOR         record separator for the print function

$"          $LIST_SEPARATOR                  list separator for the print function

$;          $SUBSCRIPT_SEPARATOR             subscript separator for multidimensional array emulation

$#          $OFMT                            format for printed numbers

$%          $FORMAT_PAGE_NUMBER              page number for file handle output

$=          $FORMAT_LINES_PER_PAGE           page length for file handle output

$-          $FORMAT_LINES_LEFT               number of lines left on the page

$~          $FORMAT_NAME                     current format

$^          $FORMAT_TOP_NAME                 current top-of-page format

$:          $FORMAT_LINE_BREAK_CHARACTERS    characters after which a string may be separated to fill continuation fields 

$^L         $FORMAT_FORMFEED                 The value a format will output for each form feed

$^A         $ACCUMULATOR                     write() accumulator for format() lines

$?          $CHILD_ERROR                     status returned by the last pipe close, backtick (``) command, or system() operator

$!          $ERRNO                           current numeric or string value of error number

$^E         $EXTENDED_OS_ERROR               Error information specific to the current operating system

$@          $EVAL_ERROR                      Perl syntax error message from the last eval() command

$$          $PROCESS_ID                      process number of the Perl running this script

$<          $REAL_USER_ID                    uid of this process

$>          $EFFECTIVE_USER_ID               effective uid of this process

$(          $REAL_GROUP_ID                   real gid of this process

$)          $EFFECTIVE_GROUP_ID              effective gid of this process

$0          $PROGRAM_NAME                    name of the file used to invoke the executing program

$[                                           index of the first element in an array and of the first character in a substring

$]          $PERL_VERSION                    version and patch level of the Perl interpreter

$^D         $DEBUGGING                       value of the debugging flags

$^F         $SYSTEM_FD_MAX                   maximum system file descriptor

$^H                                          set of syntax checks enabled by use strict and other pragmas

$^I         $INPLACE_EDIT                    value of the in-place edit extension

$^M                                          An emergency pool of allocated memory, used after an out-of-memory condition for printing error messages

$^O         $OSNAME                          name of the operating system under which this copy of Perl was built, as determined during the configuration process

$^P         $PERLDB                          internal variable for debugging support

$^R                                          The result of evaluation of the last successful regular expression

$^S                                          state of the interpreter

$^T         $BASETIME                        The time at which the script began running, in seconds since the epoch

$^W         $WARNING                         The current value of the warning switch, either true or false

$^X         $EXECUTABLE_NAME                 Perl binary

$ARGV                                        current file when reading from <>

@ARGV                                        An array that contains the command-line arguments

@INC                                         An array that contains the list of places to look for Perl scripts to be evaluated by the do EXPR, require, or use constructs (initially consists of the arguments to any -I command-line switches, followed by the default Perl library, followed by ``.'', which represents the current directory)

@_                                           Within a subroutine, an array that contains the parameters passed to that subroutine

%INC                                         A hash that contains entries for each filename that has been included via do or require (the key is the filename you specified, and the value is the location of the file actually found)

%ENV                                         A hash that contains your current environment (setting a value in %ENV changes the environment for child processes)

%SIG                                         A hash used to set signal handlers for various signals

   
    
    
  








Related examples in the same category

1.Special Literals
2.Splitting up $_
3.Splitting up $_ and creating an unnamed list
4.The list separator is a comma
5.The list separator is the empty string
6.Passing Arguments at the Command Line
7.Special Hashes: The %ENV Hash
8.The %SIG hash sets signal handlers for signals.
9.A program that changes the value of $/.
10.A program that uses the $" (dollar and quotation) variable.
11.A program that uses the $(dollar), variable.
12.A program that uses the $< variable.
13.A program that uses the $\(dollar and slash) variable.
14.A simple program that assigns to $_ using .
15.A simple version of the cat command using $_.
16.ARGV and the Null Filehandle
17.ARGV in Perl represents the command-line arguments.
18.Aliases and Values
19.Alternative names for Perl system variables.
20.Assign elements in @_ to scalar
21.Assign string array to @ARGV by using qw
22.Assign value to @_
23.Build the ARGV array with qw function
24.@_ has runtime scope.
25.A more expanded version for showing how to use the $_
26.Built-in variables: $_
27.Call-by-Reference and the @_ Array
28.Capturing fatal errors
29.Catching the sigINT signal
30.Code the $_ specifically
31.Compare value entered with number with underscore
32.Error message is stored in $!
33.Extracts information from the $] variable.
34.$! is the error number
35.$! stores the error message
36.$" is the separator
37.$# is the default format
38.$(dollar), is the separator
39.$MATCH = $&
40.$SIG{__DIE__}
41.$SIG{__WARN__} = 'IGNORE';
42.$SIG{__WARN__} = sub {die "Warning: $_[0]"};
43.$\ is 'END_OF_OUTPUT'
44.$^ is the format header
45.$^O stores the name of the operating system
46.$^S: is inside eval
47.$^W: Check the '-w switch'
48.$^X: get the Perl execuatable file name
49.$_ for print function
50.$_ stores the user input
51.$~ is the format
52.%INC values
53.File-searching program using $ARGV.
54.Get Computer Name key in the %ENV
55.Get local time from $^T
56.If $_contains needle, the string is printed.
57.Integer signal
58.Lines Remaining on the Page: $-
59.List all command line argument
60.Local builtin var
61.Locate all numbers less than 6
62.Manipuate @_ and return @_
63.Mannually change the $1 variable
64.Match: $&
65.Perl's modules reside in the directories named in the @INC array, or subdirectories
66.Perl's special arrays
67.Perl's special variables
68.Postmatch $'
69.Prematch: $`
70.Print all command line argument
71.Print the default variable's ($_) value
72.Quick Sum
73.Read and set environment variables?
74.Read lines from supplied filenames
75.Reference element in @_
76.Resetting array base
77.Retrieving the Entire Pattern: $&
78.Saving in the $& special scalar
79.Set the $/ and chomp
80.Special Variables
81.System variables that control how write sends output to a file
82.Test of open and die with $!.
83.The $_ Scalar Variable
84.The @* field
85.The @ISA Array and Calling Methods
86.The Argument Vector @ARGV
87.The Pattern-Matching Operator and $_
88.The Substitution Operator and $_
89.The code executes a line of code you type as long as that line doesn't start with a #
90.The environment associative array: Associative arrays %ENV holds your system's environment variables.
91.The following functions and operators work with the $_ variable by default:
92.The shift operator returns an undefined value if the array has no more elements.
93.To list all .pm files by using the @INC array
94.Use while loop to display all entries in ENV
95.Using $, to set the separator for print command
96.Using $_ (dollar underscore)
97.Using $_ as the array index
98.Using $_ variable with while statement
99.Using %SIG to define our own signal handlers
100.Using @_ directly
101.Using __LINE__ to output line number
102.Using eof and <> together.
103.Using the $. variable.
104.Using the $;(dollar and semicolon) variable.
105.Using the @_ to reference the parameter
106.Using the Default Variable $_
107.Using the diamond operator with @ARGV
108.Using the if statement to check the command line parameters
109.Using the special Perl variable $! in the message passed to die.
110.Using tr to convert all file names passed in to uppercase
111.Verify the total number of the command line parameter
112.Working with $_ usually makes programming much easier, but more confusing to the uninitiated
113.You display the current line of execution in a Perl script by referring to it with the __LINE__ token.
114.You display the name of the current Perl package with __PACKAGE__.
115.You display the name of the current file with the __FILE__ token
116.foreach (@_)
117.foreach loop and $_
118.or die $!
119.or die $^E;
120.print "Hello, $ENV{USER}!\n";
121.print $INC{'English.pm'};
122.print $]; (Perl version number)
123.print out all pm library location
124.prints out each element of @ARGV separately
125.shift: defaults to shifting @ARGV
126.time - $^T
127.undef $/;