Perl special variable

There are some special variables defined in the Perl language, usually prefixed with $, @, or %, for example: $_.

Many special variables have a long English name, and the operating system variable $! can be written as $OS_ERROR.

If you want to use a special variable with an English name, you need to add use English; to the program header. This allows you to use descriptive English special variables.

The most common special variable is $_, which contains the default input and pattern matching content. An example is as follows:


#!/usr/bin/perl foreach ('Google','Welookups','Programming ') print $_< Span class="hl-code">; print "n";

Execute the above program, the output is:


In the subsequent instance we do not use $_ to output content material:


#!/usr/bin/perl foreach ('Google','Welookups','Programming ') print; print "n";

Execute the above program, the output is:


In the instance, first output "Google", then output "Welookups", and ultimately output "Programming ".

In an iterative loop, the contemporary loop's string is positioned in $_ and then output via print. In addition, print does not specify an output variable, and $_ is used by default.

The following are some locations where even if you don't specify Perl, you'll assume that you use $_:

  • Various unary functions, inclusive of capabilities like ord() and int() and all documents besides "-t" ("-f", "-d"), "-t" default operation STDIN.
  • Various listing functions, which includes print() and unlink().
  • The pattern matching operations "m//", "s///" and "tr///" when the "=~" operator is not used.
  • The default generation variable for the "foreach" loop while no different variables are given.
  • Implicit new release variables for the grep() and map() capabilities.
  • When "at the same time as" has most effective one situation and the condition is to check the result of the "" operation, $_ is the default region for the enter record. This does now not take place besides for the "whilst" test circumstance. (Mnemonic: Underscores can be overlooked in positive operations.)

Special variable kind

Depending on the nature of the use of unique variables, they may be divided into the subsequent classes:

  • Global scalar unique variables.

  • Global array special variables.

  • Global hash special variables.

  • Global special report take care of.

  • Global special constants.

  • Regular expression special variables.

  • File manage special variable.

Global scalar unique variable

The following is a listing of all scalar unique variables, inclusive of special characters and variables in English:

$_ The default enter and sample in shape content.
$. The current line wide variety of the file take care of that changed into study ultimate time
$/ Enter a document separator, the default is a newline character. If you operate the undef variable, you'll study the cease of the record.
$, Output field separator
$ Output report separator
$" This variable is similar to $, but is implemented to interpolate arrays and strings in double quotes (or comparable interpolated strings) and The case of slice values. The default is a area.
$; The separator used when simulating multidimensional arrays. The default is "
$^H The syntax check status activated by the compiler
$^I The value of the built-in control editor
$^M The size of the alternate memory pool
$^O Operating system name
$^P Specify the internal variables of the current debug value
$^T Starting from the beginning of the new century, the time in which the footsteps start running in seconds
$^W The current value of the warning switch
$^X The name of the Perl binary executable
$ARGV The current file name when reading from the default file handle

Global array unique variable

@ARGV List of command line arguments handed to the script
@INC List of directories to search whilst importing modules
@F Command line array enter

Global hash unique variable


The hash table %INC contains all the files contained in the do or require announcement. The key-word is the record call and the price is the path to this report


Include present day surroundings variables


Signal listing and how it's far dealt with

Global special record manage


Through the unique file take care of for all report names in the array variable @ARGV


Standard Error Output Handle


Standard enter deal with


Standard output take care of


The unique document take care of references any content material after the __END__ flag inside the file that includes the script content material. Or confer with the whole thing that carries the __DATA__ flag within the document, as long as you have examine data in the equal bundle, __DATA__ exists.

_ (underscore)

Special file handles are used to cache file statistics (fstat, stat, and lstat).

Global unique constants


The common sense of the script ends, ignoring the text that follows.


cutting-edge record call


cutting-edge line range


The present day package deal name, the default package call is fundamental.

Regular expression special variable


Includes the nth substring of the remaining pattern healthy


The string of the previous a hit sample match



Previous healthy before the a hit substring



Content after the closing matching a success substring



The remaining enclosure that suits the last regular articulation look for design. For example:

/Version: (.*)deal with special

If set to zero, the element fflush is precisely known as after each name to the capacity compose or print, and the composed substance material is composed again to the report.



Current yield page wide assortment



The present day length of each website page. The default is 60.



The number of columns shutting at the contemporary website page



The call of the cutting edge report yield design. The default is the archive handle call.



The call of the contemporary report yield header design. The default esteem is the record manage call with the postfix "_TOP".


welookups is optimized for learning.© welookups. 2018 - 2020 All Right Reserved and you agree to have read and accepted our term and condition.