home PYTHONJAVA
 

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:

Instance

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

Execute the above program, the output is:

Google
Welookups
Programming 

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

Instance

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

Execute the above program, the output is:

Google
Welookups
Programming 

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.
$ARG
$. The current line wide variety of the file take care of that changed into study ultimate time
$NR
$/ Enter a document separator, the default is a newline character. If you operate the undef variable, you'll study the cease of the record.
$RS
$, Output field separator
$OFS
$ Output report separator
$ORS
$" 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.
$LIST_SEPARATOR
$; 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
$INPLACE_EDIT
$^M The size of the alternate memory pool
$^O Operating system name
$OSNAME
$^P Specify the internal variables of the current debug value
$PERLDB
$^T Starting from the beginning of the new century, the time in which the footsteps start running in seconds
$BASETIME
$^W The current value of the warning switch
$WARNING
$^X The name of the Perl binary executable
$EXECUTABLE_NAME
$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

%INC

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

%ENV

Include present day surroundings variables

%SIG

Signal listing and how it's far dealt with

Global special record manage

ARGV

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

STDERR

Standard Error Output Handle

STDIN

Standard enter deal with

STDOUT

Standard output take care of

DATA

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

__END__

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

__FILE__

cutting-edge record call

__LINE__

cutting-edge line range

__PACKAGE__

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

Regular expression special variable

$n

Includes the nth substring of the remaining pattern healthy

$&

The string of the previous a hit sample match

$MATCH

$`

Previous healthy before the a hit substring

$PREMATCH

$'

Content after the closing matching a success substring

$POSTMATCH

$+

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.

$OUTPUT_AUTOFLUSH

$%

Current yield page wide assortment

$FORMAT_PAGE_NUMBER

$=

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

$FORMAT_LINES_PER_PAGE

$-

The number of columns shutting at the contemporary website page

$FORMAT_LINES_LEFT

$~

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

$FORMAT_NAME

$^

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

$FORMAT_TOP_NAME






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