Perl Special Variables
Perl language defines some special variable, usually $, @, or% as a prefix, for example: $ _.
Many special variables have a very long English name, operating system variable $! Can be written as $ OS_ERROR.
If you want to use the English name of a special variable in the program need to head to adduse English;.This English special variables descriptive.
The most commonly used special variable $ _, the variable contains the default input and pattern matching content. Examples are as follows:
#!/usr/bin/perl foreach ('Google','w3big','Taobao') { print $_; print "\n"; }
The above program, the output is:
Google w3big Taobao
The following example we do not use $ _ to output:
#!/usr/bin/perl foreach ('Google','w3big','Taobao') { print; print "\n"; }
The above program, the output is:
Google w3big Taobao
Example, the first output "Google", then output "w3big", the final output "Taobao".
In the iteration loop, current loop of string in $ _ and then through the print output. Also print without specifying the output variable is used by default of $ _.
The following are a few states even without Perl will assume $ _ place:
- Monocular various functions, including as ord () and int () function, and so in addition to "-t" all file tests ( "-f", "- d"), "- t" default action STDIN.
- A list of the various functions, such as print () and unlink ().
- Do not use the "= ~" operator mode when the matching operation "m //", "s ///" and "tr ///".
- When other variables are not given "foreach" loop iteration variable default.
- Implicit iteration variable grep () and map () function.
- When "while" only only condition, and the condition is the result of "" operation test, $ _ is the default location for storing the input records. In addition to the "while" test conditions that would not happen. (Mnemonic: underline in a particular operation can be omitted.)
Special Variable Types
According to the special nature of the use of variables can be divided into the following categories:
Special global scalar variable.
Special global array variable.
Hash special global variables.
Global special file handle.
Global special constant.
Regex special variables.
File handle special variables.
Special global scalar variable
Following is a list of all the special scalar variable containing special characters and English in the form of variables:
$ _ | The default input and pattern matching content. |
$ ARG | |
$. | Previous read current line number of file handles |
$ NR | |
$ / | Input record separator, by default a newline character. As with undef this variable will read the end of the file. |
$ RS | |
$, | Output field separator |
$ OFS | |
$ \ | The output record separator |
$ ORS | |
$ " | The same $ variable, similar, but applied to the string enclosed in double quotes (or similar string interpolation) is inserted within the array of occasions and slice values. The default is a blank. |
$ LIST_SEPARATOR | |
$; | Delimiter used when a multidimensional array emulation. The default is "\ 034." |
$ SUBSCRIPT_SEPARATOR | |
$ ^ L | Sent to the output channels take the paper feed character. The default is "\ f". |
$ FORMAT_FORMFEED | |
$: | The current set of characters after which a string may be broken to fill continuation fields (starting with ^) in a format. Default is "\ n" ". |
$ FORMAT_LINE_BREAK_CHARACTERS | |
$ ^ A | Before printing variable data format for saving |
$ ACCUMULATOR | |
$ # | When you print digital default digital output format (obsolete). |
$ OFMT | |
$? | Return to the state of an external command |
$ CHILD_ERROR | |
$! | Numeric value of this variable is the value of errno, string value is the corresponding system error string |
$ OS_ERROR or $ ERRNO | |
$ @ | The eval command error message if it is empty, it means the last eval command completed successfully |
$ EVAL_ERROR | |
$$ | Perl script to run the current process ID |
$ PROCESS_ID or $ PID | |
$ < | The actual subscriber numbers of the current process |
$ REAL_USER_ID or $ UID | |
$> | Effective user number of the current process |
$ EFFECTIVE_USER_ID or $ EUID | |
$ ( | The current process actual number of user groups |
$ REAL_GROUP_ID or $ GID | |
$) | The current process's effective user group number |
$ EFFECTIVE_GROUP_ID or $ EGID | |
$ 0 | The file name contains the script being executed |
$ PROGRAM_NAME | |
$ [ | Index of the first element of the array of arrays, the default is 0. |
$] | Perl version number |
$ PERL_VERSION | |
$ ^ D | The value of the debug flag |
$ DEBUGGING | |
$ ^ E | In non-UNIX operating system environments extended error information |
$ EXTENDED_OS_ERROR | |
$ ^ F | Maximum file identifier value of said bundle |
$ SYSTEM_FD_MAX | |
$ ^ H | Activated by the compiler syntax checking status |
$ ^ I | Built-in control value of the editor |
$ INPLACE_EDIT | |
$ ^ M | Size spare memory pool |
$ ^ O | Operating system name |
$ OSNAME | |
$ ^ P | Specifies the current debugger internal variable value |
$ PERLDB | |
$ ^ T | Since the beginning of the new century, the pace of the seconds start to run out of time |
$ BASETIME | |
$ ^ W | The current value of the warning switch |
$ WARNING | |
$ ^ X | Perl binary executable code name |
$ EXECUTABLE_NAME | |
$ ARGV | Current file name read from the default file handle when |
Special global array variable
@ARGV | To the script command line argument list |
@INC | When you import the module directory list to be searched |
@F | Enter the command line array |
Hash special global variables
% INC | Hash% INC contains all the files with a do or require statements contained Keyword is the file name, the value is the path of the file |
% ENV | Containing the current environment variable |
% SIG | Signal list and how to deal |
Global special file handle
ARGV | Special file handle through the array variable @ARGV all file names |
STDERR | Standard output handle error |
STDIN | Standard input handle |
STDOUT | Standard output handle |
DATA | Special file handle reference any content __END__ flag in the file containing the contents of the script after. Or a reference to all of the content file contains __DATA__ flag after, as long as you have read in the same packet data, __ DATA__ there. |
_ (Underscore) | Special file handle cache files for information (fstat, stat and lstat). |
Global special constant
__END__ | The logical end of the script, the text after ignored. |
__FILE__ | Current file name |
__LINE__ | The current line number |
__PACKAGE__ | The current package name, the default package name is main. |
Regex special variables
$ N | Containing the last pattern matching n th string |
$ & | Previous successful pattern matching string |
$ MATCH | |
$ ` | Last substring matching the success of the previous content |
$ PREMATCH | |
$ ' | Content last successful match after substring |
$ POSTMATCH | |
$ + | And the last regular expression search last parenthesis matching format. E.g: /Version: (.*)|Revision: (.*)/ && ($rev = $+); |
$ LAST_PAREN_MATCH |
File handle special variables
$ | | If set to zero after each function call write or print, automatically calls the function fflush, written content will write the file |
$ OUTPUT_AUTOFLUSH | |
$% | The current output page number |
$ FORMAT_PAGE_NUMBER | |
$ = | The current page length. The default is 60. |
$ FORMAT_LINES_PER_PAGE | |
$ - | The current page number of lines remaining |
$ FORMAT_LINES_LEFT | |
$ ~ | The current name of the report output format. The default value is the name of the file handle. |
$ FORMAT_NAME | |
$ ^ | The current report output table name header format. The default value is with the suffix "_TOP" file handle name. |
$ FORMAT_TOP_NAME |