📄 ch12.htm
字号:
</TD></TR>
<TR><TD WIDTH=127><CENTER><TT>STDOUT</TT></CENTER>
</TD><TD WIDTH=463>This file handle is used to send output to the standard output file. Normally, this is the display, but it can be changed.
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Table 12.2 puts the variables into different categories so you
can see how they relate to one another. This organization is better
than Table 12.1 when you are creating your own programs. Some
of the categories covered in Table 12.2 have their own chapters.
The subheadings in the table point out which chapter you can look
at for more information.<BR>
<P>
<CENTER><B>Table 12.2 Perl's Special Variables</B></CENTER>
<p>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR><TD WIDTH=115><CENTER><I>Variable Name</I></CENTER></TD><TD WIDTH=475><I>Description</I>
</TD></TR>
<TR><TD COLSPAN=2 WIDTH=590><B>Variables That Affect Arrays</B>
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$"</TT></CENTER>
</TD><TD WIDTH=475>The separator used between list elements when an array variable is interpolated into a double-quoted string. Normally, its value is a space character.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$[</TT></CENTER>
</TD><TD WIDTH=475>Holds the base array index. Normally, set to 0. Most Perl authors recommend against changing it without a very good reason.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$;</TT></CENTER>
</TD><TD WIDTH=475>Holds the subscript separator for multidimensional array emulation. Its use is beyond the scope of this book. For a more in-depth look at Perl programming, see Que's <I>Special Edition Using Perl for Web Programming</I>.
</TD></TR>
<TR><TD COLSPAN=2 WIDTH=590><B>Variables Used with Files (See <A HREF="ch9.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch9.htm" >Chapter 9</A> "Using Files")</B>
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$.</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the current record or line number of the file handle last read. It is read-only and will be reset to 0 when the file handle is closed.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$/</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the input record separator. The record separator is usually the newline character. However, if <TT>$/</TT> is set to an empty string, two or more newlines in the input file will be treated as one.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$|</TT></CENTER>
</TD><TD WIDTH=475>This variable, if nonzero, will flush the output buffer after every <TT>write()</TT> or <TT>print()</TT> fuNCtion. Normally, it is set to 0.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^F</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the value of the maximum system file description. Normally, it's set to 2. The use of this variable is beyond the scope of this book.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$ARGV</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the name of the current file being read when using the diamond operator <TT>(<>)</TT>.
</TD></TR>
<TR><TD WIDTH=115><CENTER>_</CENTER></TD><TD WIDTH=475>This file handle (the underscore) can be used when testing files. If used, the information about the last file tested will be used to evaluate the latest test.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>DATA</TT></CENTER>
</TD><TD WIDTH=475>This file handle refers to any data following <TT>__END__</TT>.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>STDERR</TT></CENTER>
</TD><TD WIDTH=475>This file handle is used to send output to the standard error file. Normally, this is connected to the display, but it can be redirected if needed.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>STDIN</TT></CENTER>
</TD><TD WIDTH=475>This file handle is used to read input from the standard input file. Normally, this is connected to the keyboard, but it can be changed.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>STDOUT</TT></CENTER>
</TD><TD WIDTH=475>This file handle is used to send output to the standard output file. Normally, this is the display, but it can be changed.
</TD></TR>
<TR><TD COLSPAN=2 WIDTH=590><B>Variables Used with Patterns (See <A HREF="ch10.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch10.htm" >Chapter 10</A>, "Regular Expressions")</B>
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$&</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the string that was matched by the last successful pattern match.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$`</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the string that preceded whatever was matched by the last successful pattern match.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$´</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the string that followed whatever was matched by the last successful pattern match.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$+</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the string matched by the last bracket in the last successful pattern match. For example, the statement <TT>/Fieldname: (.*)|Fldname: (.*)/ && ($fName = $+);</TT> will find the name of a field even if you
don't know which of the two possible spellings will be used.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$*</TT></CENTER>
</TD><TD WIDTH=475>This variable changes the interpretation of the <TT>^</TT> and <TT>$</TT> pattern aNChors. Setting <TT>$*</TT> to 1 is the same as using the <TT>/m</TT> option with the regular expression matching and substitution operators. Normally,
<TT>$*</TT> is equal to 0.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$<number></TT></CENTER>
</TD><TD WIDTH=475>This group of variables (<TT>$1</TT>, <TT>$2</TT>, <TT>$3</TT>, and so on) holds the regular expression pattern memory. Each set of parentheses in a pattern stores the string that matches the components surrounded by the parentheses
into one of the <TT>$<number></TT> variables.
</TD></TR>
<TR><TD COLSPAN=2 WIDTH=590><B>Variables Used with Printing</B>
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$,</TT></CENTER>
</TD><TD WIDTH=475>This variable is the output separator for the <TT>print()</TT> fuNCtion. Normally, this variable is an empty string. However, setting <TT>$,</TT> to a newline might be useful if you need to print each element in the parameter list on a
separate line.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$\</TT></CENTER>
</TD><TD WIDTH=475>The variable is added as an invisible last element to the parameter list passed to the <TT>print()</TT> fuNCtion. Normally, it's an empty string, but if you want to add a newline or some other suffix to everything that is printed, you
can assign the suffix to <TT>$\</TT>.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$#</TT></CENTER>
</TD><TD WIDTH=475>This variable is the default format for printed numbers. Normally, it's set to <TT>%.20g</TT>, but you can use the format specifiers covered in by the section "Example: Printing Revisited" in <A HREF="ch9.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch9.htm" >Chapter 9</A>to
specify your own default format.
</TD></TR>
<TR><TD COLSPAN=2 WIDTH=590><B>Variables Used with Processes (See <A HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, "Handling Errors and Signals")</B>
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$$</TT></CENTER>
</TD><TD WIDTH=475>This UNIX-based variable holds the process number of the process running the Perl interpreter.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$?</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the status of the last pipe close, back-quote string, or <TT>system()</TT> fuNCtion. More information about the <TT>$?</TT> variable can be found in <A HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, "Handling Errors and
Signals."
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$0</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the name of the file containing the Perl script being executed.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$]</TT></CENTER>
</TD><TD WIDTH=475>This variable holds a string that identifies which version of Perl you are using. When used in a numeric context, it will be equal to the version number plus the patch level divided by 1000.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$!</TT></CENTER>
</TD><TD WIDTH=475>This variable, when used in a numeric context, holds the current value of <TT>errno</TT>. If used in a string context, it will hold the error string associated with <TT>errno</TT>. For more information about <TT>errno</TT>, see <A
HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, "Handling Errors and Signals."
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$@</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the syntax error message, if any, from the last <TT>eval()</TT> fuNCtion call. For more information about <TT>errno</TT>, see <A HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, "Handling Errors and Signals."
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$<</TT></CENTER>
</TD><TD WIDTH=475>This UNIX-based variable holds the read <TT>uid</TT> of the current process.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$></TT></CENTER>
</TD><TD WIDTH=475>This UNIX-based variable holds the effective <TT>uid</TT> of the current process.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$)</TT></CENTER>
</TD><TD WIDTH=475>This UNIX-based variable holds the read <TT>gid</TT> of the current process. If the process belongs to multiple groups, then <TT>$)</TT> will hold a string consisting of the group names separated by spaces.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^T</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the time, in seconds, at which the script begins running.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^X</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the full pathname of the Perl interpreter being used to run the current script.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>%ENV</TT></CENTER>
</TD><TD WIDTH=475>This hash variable contains entries for your current environment variables. Changing or adding an entry will affect only the current process or a child process, never the parent process. See the section "Example: Using the
<TT>%ENV</TT> Variable" later in this chapter.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>%SIG</TT></CENTER>
</TD><TD WIDTH=475>This hash variable contains entries for signal handlers. For more information about signal handlers, see <A HREF="ch13.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch13.htm" >Chapter 13</A>, "Handling Errors and Signals."
</TD></TR>
<TR><TD COLSPAN=2 WIDTH=590><B>Variables Used with Reports (see <A HREF="ch11.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch11.htm" >Chapter 11</A>, "Creating Reports")</B>
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$%</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the current page number for the default file handle. If you use <TT>select()</TT> to change the default file handle, <TT>$%</TT> will change to reflect the page number of the newly selected file handle.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$=</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the current page length for the default file handle. Changing the default file handle will change <TT>$=</TT> to reflect the page length of the new file handle.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$-</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the number of lines left to print for the default file handle. Changing the default file handle will change <TT>$-</TT> to reflect the number of lines left to print for the new file handle.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$~</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the name of the default line format for the default file handle. Normally, it is equal to the file handle's name.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the name of the default heading format for the default file handle. Normally, it is equal to the file handle's name with <TT>_TOP</TT> appended to it.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$:</TT></CENTER>
</TD><TD WIDTH=475>This variable holds a string that consists of the characters that can be used to end a word when word-wrapping is performed by the <TT>^</TT> report formatting character. Normally, the string consists of the space, newline, and dash
characters.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^L</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the string used to eject a page for report printing. <A HREF="ch11.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch11.htm" >Chapter 11</A>, "Creating Reports," shows how to use this variable to create simple footers.
</TD></TR>
<TR><TD COLSPAN=2 WIDTH=590><B>Miscellaneous Variables</B></TD>
</TR>
<TR><TD WIDTH=115><CENTER><TT>$_</TT></CENTER>
</TD><TD WIDTH=475>This variable is used as the default parameter for a lot of fuNCtions.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^D</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the current value of the debugging flags. For more information, see <A HREF="ch16.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch16.htm" >Chapter 16</A>, "Debugging Perl."
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^I</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the file extension used to create a backup file for the in-place editing specified by the <TT>-i</TT> command line option. For example, it could be equal to ".bak."
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^P</TT></CENTER>
</TD><TD WIDTH=475>This variable is an internal flag that the debugger clears so that it will not debug itself.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>$^W</TT></CENTER>
</TD><TD WIDTH=475>This variable holds the current value of the <TT>-w</TT> command line option.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>@ARGV</TT></CENTER>
</TD><TD WIDTH=475>This array variable holds a list of the command line arguments. You can use <TT>$#ARGV</TT> to determine the number of arguments minus one.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>@F</TT></CENTER>
</TD><TD WIDTH=475>This array variable holds the list returned from autosplit mode. Autosplit mode is associated with the <TT>-a</TT> command line option.
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>@INC</TT></CENTER>
</TD><TD WIDTH=475>This array variable holds a list of directories where Perl can look for scripts to execute. The list is used mainly by the require statement. You can find more information about <TT>require</TT> statements in <A HREF="ch15.htm" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/ch15.htm" >Chapter
15</A>, "Perl Modules."
</TD></TR>
<TR><TD WIDTH=115><CENTER><TT>%INC</TT></CENTER>
</TD><TD WIDTH=475>This hash variable has entries for each filename iNCluded by <TT>do</TT> or <TT>require</TT> statements. The key of the hash entries are the filenames and the values are the paths where the files were found.
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Most of these variables are discussed in other chapters of the
book, and some of the variables are simple enough to use that
you don't need to see examples by this time. However, the DATA
file handle and the %ENV associated array deserve some additional
mention. They are discussed in the following sections.
<H3><A NAME="ExampleUsingtheTTFONTSIZEFACECourierDATAFONTTTFONTSIZEFileHandleFONT">
Example: Using the <TT>DATA </TT>File
Handle</FONT></A></H3>
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -