Perl special variable
Some special variables are defined in the Perl language, usually with $, s, or % as prefixes, such as$.
Many special variables have a very long English name, operating system variable $! It 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 head of the program; /b10>。 This allows you to use descriptive English special variables.
The most common special variable is $, which contains the default input and pattern matching content. Here's an example:
#!/usr/bin/perl foreach ('Google','W3CSchool','Taobao') { print $_; print "\n"; }
The above procedure is performed and the output is:
Google W3CSchool Taobao
The following examples do not use $? to output content:
#!/usr/bin/perl foreach ('Google','W3CSchool','Taobao') { print; print "\n"; }
The above procedure is performed and the output is:
Google W3CSchool Taobao
In the example, "Google" is output first, "W3CSchool" is output, and finally "Taobao" is output.
In an iterative loop, the string of the current loop is placed in $, and then output by print. I n addition, print does not specify an output variable, which is also used by default.
Here are a few places where Perl would be assumed to use $?
- Various monoclith functions, including functions such as ord() and int(), as well as all but "-t" file test operations ("-f", "-d"), "-t" default operation STDIN.
- Various list functions, such as print() and unlink().
- The pattern matching operations "m/", "s///" and "tr///" are not used with the "
- The default iterative variable for the "foreach" loop is not given.
- The implied iterative variables of the grep() and map() functions.
- When "while" has only one condition, and the condition is a test of the results of the "" operation, $is the default location where the input record is stored. T his does not happen except for the "while" test condition. ( mingo: Underscores can be omitted in specific operations.) )
Special variable type
Depending on the nature of the use of special variables, they can be divided into the following categories:
-
A special variable for global se00.
-
Global array special variables.
-
The global hash special variable.
-
Global special file handle.
-
Global special constant.
-
Regular expression special variables.
-
File handle special variable.
A special variable for global se00
The following is a list of all the special variables in the standard, including special characters and variables in English:
$_ | The default input and pattern match. |
$ARG | |
$. | The current line number of the previously read file handle |
$NR | |
$/ | Enter the record separator, which defaults to a new line of characters. If you use the underf variable, you will read to the end of the file. |
$RS | |
$, | The output domain separator |
$OFS | |
$\ | The output record separator |
$ORS | |
$" | The variable is similar to $, but applies to situations where arrays and slice values are interpoled into strings (or similar interpolation strings) caused by double quotes. The default is a space. |
$LIST_SEPARATOR | |
$; | The separator used when simulating a multi-dimensional array. The default is .034. |
$SUBSCRIPT_SEPARATOR | |
$^L | The paper changer sent to the output channel. T he default is """" |
$FORMAT_FORMFEED | |
$: | The current set of characters after which a string may be broken to fill continuation fields (starting with ^) in a format. D efault is "\n"". |
$FORMAT_LINE_BREAK_CHARACTERS | |
$^A | The variable used to hold the formatted data before printing |
$ACCUMULATOR | |
$# | The default digital output format (abandoned) when printing numbers. |
$OFMT | |
$? | Returns the status of the previous external command |
$CHILD_ERROR | |
$! | The numeric value of this variable is the value of errno, and the string value is the corresponding system error string |
$OS_ERROR or $ERRNO | |
$@ | The error message for the command eval. If empty, the last eval command was executed successfully |
$EVAL_ERROR | |
$$ | The process number of the current Perl scripter |
$PROCESS_ID or $PID | |
$< | The actual user number of the current process |
$REAL_USER_ID or $UID | |
$> | The valid user number for the current process |
$EFFECTIVE_USER_ID or $EUID | |
$( | The actual group user number of the current process |
$REAL_GROUP_ID or $GID | |
$) | The valid group user number for the current process |
$EFFECTIVE_GROUP_ID or $EGID | |
$0 | The file name that contains the script being executed |
$PROGRAM_NAME | |
$[ | The lower sign of the first element of the array array, the default is 0. |
$] | Perl's version number |
$PERL_VERSION | |
$^D | The value of the debug flag |
$DEBUGGING | |
$^E | The operating system extension error message in a non-UNIX environment |
$EXTENDED_OS_ERROR | |
$^F | The maximum file bundle number |
$SYSTEM_FD_MAX | |
$^H | The syntax activated by the compiler checks the status |
$^I | The value of the built-in control editor |
$INPLACE_EDIT | |
$^M | The size of the spare memory pool |
$^O | The name of the operating system |
$OSNAME | |
$^P | Specifies the internal variable of the current debug value |
$PERLDB | |
$^T | From the beginning of the new century, the footsteps are calculated in seconds to start running time |
$BASETIME | |
$^W | The current value of the warning switch |
$WARNING | |
$^X | The name of the Perl binary executable code |
$EXECUTABLE_NAME | |
$ARGV | The current file name when read from the default file handle |
Global array special variables
@ARGV | A list of command line parameters passed to the script |
@INC | A list of directories that need to be searched when importing modules |
@F | Array input on the command line |
The global hash special variable
%INC |
Hash%INC contains all files contained with do or require statements. The keyword is the file name and the value is the path to the file |
%ENV |
Contains the current environment variable |
%SIG |
The list of signals and how they are processed |
Global special file handle
Argv |
A special file handle that traverses @ARGV all file names in an array variable |
STDERR |
The standard error output handle |
Stdin |
The standard input handle |
STDOUT |
The standard output handle |
DATA |
The special file handle refers to anything in the file __END__ after the flag contains script content. O r refer to everything that contains the __DATA__ the file, as long as you have read data in the same package, __DATA__ exists. |
(underlined) |
Special file handles are used to cache file information (fstat, stat, and lstat). |
Global special constant
__END__ |
The logical end of the script ignores the text that follows. |
__FILE__ |
The current file name |
__LINE__ |
The current line number |
__PACKAGE__ |
The current package name, the default package name is main. |
Regular expression special variables
$n |
Contains the nth subchain of the last pattern match |
$& |
The string matched by the previous successful pattern |
$MATCH |
|
$` |
The content before the previous match successful sub-string |
$PREMATCH |
|
$' |
The content after the previous match successful subchain |
$POSTMATCH |
|
$+ |
The last parenthesis that matches the last regular expression search format. For example: /Version: (.*)|Revision: (.*)/ && ($rev = $+); |
$LAST_PAREN_MATCH |
File handle special variable
$| |
If set to zero, after each call to the function write or print, the function fflush is automatically called and the written content is written back to the file |
$OUTPUT_AUTOFLUSH |
|
$% |
The current output page number |
$FORMAT_PAGE_NUMBER |
|
$= |
The current length per page. T he default is 60. |
$FORMAT_LINES_PER_PAGE |
|
$- |
The number of rows remaining on the current page |
$FORMAT_LINES_LEFT |
|
$~ |
The name of the current report output format. T he default is the file handle name. |
$FORMAT_NAME |
|
$^ |
The name of the current report output header format. T he default is the file handle name _TOP suffix ," "I don't know." |
$FORMAT_TOP_NAME |