ch28_01.htm

来自「编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,」· HTM 代码 · 共 360 行

HTM
360
字号
<html><head><title>Special Names (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="Special Names"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="part5.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="part5.htm">Part 5: Reference Material</a></td><td align="right" valign="top" width="172"><a href="ch28_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h1 class="chapter">Chapter 28.  Special Names</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4><p><a href="ch28_01.htm">Special Names Grouped by Type</a><br><a href="ch28_02.htm">Special Variables in Alphabetical Order</a><br></p></div><p>This chapter is about variables that have special meanings toPerl.  Most of the punctuational names have reasonable mnemonics, oranalogs in one of the shells (or both).  But if you want to use longvariable names as synonyms, just say:<blockquote><pre class="programlisting">use English;</pre></blockquote>at the top of your program.  This aliases all the short names to longnames in the current package.  Some of these variables even havemedium names, generally borrowed from <em class="emphasis">awk</em>.  Mostpeople eventually settle on using the short names, at least for themore commonly used variables.  Throughout this book, we consistentlyrefer to the short names, but also often mention the long names (inparentheses) so that you can look them up easily in this chapter.</p><p>The semantics of these variables can be quite magical.  (To createyour own magic, see <a href="ch14_01.htm">Chapter 14, "Tied Variables"</a>.)  Afew of these variables are read-only.  If you try to assign values tothem, an exception will be raised.</p><p>In what follows, we'll first provide a concise listing of thevariables and functions for which Perl assigns a special meaning,grouped by type, so you can look up variables that you're notsure of the proper name.  Then we'll explain all of the variablesalphabetically under their proper name (or their least improper name).</p><h2 class="sect1">28.1. Special Names Grouped by Type</h2><p>We used the word "type" loosely--the sections here actually groupvariables more by their scope, that is, where they're visible from.</p><h3 class="sect2">28.1.1. Regular Expression Special Variables</h3><p>The following special variables related to pattern matchingare visible throughout the dynamic scope in which the pattern matchoccurred (except for <tt class="literal">$*</tt>, which is deprecated).  In other words,they behave as though they were declared with <tt class="literal">local</tt>, so you needn'tdeclare them that way yourself.  See <a href="ch05_01.htm">Chapter 5, "Pattern Matching"</a>.<blockquote><pre class="programlisting">$*$<em class="replaceable">digits</em>@+ (@LAST_MATCH_END)@- (@LAST_MATCH_START)$+ ($LAST_PAREN_MATCH)$^R ($LAST_REGEXP_CODE_RESULT)$&amp; ($MATCH)$' ($POSTMATCH)$` ($PREMATCH)</pre></blockquote></p><h3 class="sect2">28.1.2. Per-Filehandle Variables</h3><p>These special variables never need to be mentioned in a <tt class="literal">local</tt>because they always refer to some value pertaining to the currentlyselected output filehandle--each filehandle keeps its own set ofvalues.  When you <tt class="literal">select</tt> another filehandle, the old filehandleremembers the values it had for these variables, and the variablesnow reflect the values of the new filehandle.  See also the<tt class="literal">FileHandle</tt> module in <a href="ch32_01.htm">Chapter 32, "Standard Modules"</a>.<blockquote><pre class="programlisting">$| ($AUTOFLUSH, $OUTPUT_AUTOFLUSH)$- ($FORMAT_LINES_LEFT)$= ($FORMAT_LINES_PER_PAGE)$~ ($FORMAT_NAME)$% ($FORMAT_PAGE_NUMBER)$^ ($FORMAT_TOP_NAME)</pre></blockquote></p><h3 class="sect2">28.1.3. Per-Package Special Variables</h3><p>These special variables exist separately in each package.There should be no need to localize them, since <tt class="literal">sort</tt> automaticallydoes so on <tt class="literal">$a</tt> and <tt class="literal">$b</tt>, and the rest are probably best left alone(though you will need to declare them with <tt class="literal">our</tt> if you <tt class="literal">use strict</tt>).<blockquote><pre class="programlisting">$a$b@EXPORT@EXPORT_OK%EXPORT_TAGS%FIELDS@ISA%OVERLOAD$VERSION</pre></blockquote></p><h3 class="sect2">28.1.4. Program-wide Special Variables</h3><p>These variables are truly global in the fullest sense--they mean thesame thing in every package, because they're all forced into package<tt class="literal">main</tt> when unqualified (except for<tt class="literal">@F</tt>, which is special in <tt class="literal">main</tt>, butnot forced).  If you want a temporary copy of one of these, you mustlocalize it in the current dynamic scope.</p><table border="1"><tr><td><p><blockquote><pre class="programlisting">%ENV%INC%SIG%!%^H@_@ARGV@F@INC$_ ($ARG)$0 ($PROGRAM_NAME)$ARGV$! ($ERRNO, $OS_ERROR)$" ($LIST_SEPARATOR)$#$$ ($PID, $PROCESS_ID)$( ($GID, $REAL_GROUP_ID)$) ($EGID, $EFFECTIVE_GROUP_ID)$, ($OFS, $OUTPUT_FIELD_SEPARATOR)$. ($NR, $INPUT_LINE_NUMBER)$/ ($RS, $INPUT_RECORD_SEPARATOR)$: ($FORMAT_LINE_BREAK_CHARACTERS)$; ($SUBSEP, $SUBSCRIPT_SEPARATOR)</pre></blockquote></p></td><td><p><blockquote><pre class="programlisting">$&lt; ($UID, $REAL_USER_ID)$&gt; ($EUID, $EFFECTIVE_USER_ID)$? ($CHILD_ERROR)$@ ($EVAL_ERROR)$[$\ ($ORS, $OUTPUT_RECORD_SEPARATOR)$]  ($OLD_PERL_VERSION)$^A ($ACCUMULATOR)$^C ($COMPILING)$^D ($DEBUGGING)$^E ($EXTENDED_OS_ERROR)$^F ($SYSTEM_FD_MAX)$^H$^I ($INPLACE_EDIT)$^L ($FORMAT_FORMFEED)$^M$^O ($OSNAME)$^P ($PERLDB)$^R ($LAST_REGEXP_CODE_RESULT)$^S (EXCEPTIONS_BEING_CAUGHT)$^T ($BASETIME)$^V ($PERL_VERSION)$^W ($WARNING)${^WARNING_BITS}${^WIDE_SYSTEM_CALLS}$^X ($EXECUTABLE_NAME)</pre></blockquote></p></td></tr></table><h3 class="sect2">28.1.5. Per-Package Special Filehandles</h3><p>Except for <tt class="literal">DATA</tt>, which is always per-package, the following filehandles are always assumed tobe in <tt class="literal">main</tt> when not fully qualified with another package name:<blockquote><pre class="programlisting">_ (underline)ARGVARGVOUTDATASTDINSTDOUTSTDERR</pre></blockquote></p><h3 class="sect2">28.1.6. Per-Package Special Functions</h3><p>The following subroutine names have a special meaningto Perl.  They're always called implicitly because of some event,such as accessing a tied variable or trying to call an undefinedfunction.  We don't describe them in this chapter since they allreceive heavy-duty coverage elsewhere in the book.</p><p>Undefined function call interceptor (see <a href="ch10_01.htm">Chapter 10, "Packages"</a>):</p><blockquote><pre class="programlisting">AUTOLOAD</pre></blockquote><p>Moribund objects' finalization (see <a href="ch12_01.htm">Chapter 12, "Objects"</a>):</p><blockquote><pre class="programlisting">DESTROY</pre></blockquote><p>Exception objects (see <tt class="literal">die</tt> in the next chapter):</p><blockquote><pre class="programlisting">PROPAGATE</pre></blockquote><p>Auto-init and auto-cleanup functions (see <a href="ch18_01.htm">Chapter 18, "Compiling"</a>):</p><blockquote><pre class="programlisting">BEGIN, CHECK, INIT, END</pre></blockquote><p>Tie methods (see <a href="ch14_01.htm">Chapter 14, "Tied Variables"</a>):</p><blockquote><pre class="programlisting">BINMODE, CLEAR, CLOSE, DELETE, EOF, EXISTS, EXTEND, FETCH, FETCHSIZE,FILENO, FIRSTKEY, GETC, NEXTKEY, OPEN, POP, PRINT, PRINTF, PUSH, READ,READLINE, SEEK, SHIFT, SPLICE, STORE, STORESIZE, TELL, TIEARRAY,TIEHANDLE, TIEHASH, TIESCALAR, UNSHIFT, WRITE</pre></blockquote><a name="INDEX-4386"></a><a name="INDEX-4387"></a><!-- BOTTOM NAV BAR --><hr width="515" align="left"><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="part5.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0"></a></td><td align="right" valign="top" width="172"><a href="ch28_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">Part 5. Reference Material</td><td align="center" valign="top" width="171"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0"></a></td><td align="right" valign="top" width="172">28.2. Special Variables in Alphabetical Order</td></tr></table></div><hr width="515" align="left"><!-- LIBRARY NAV BAR --><img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"> <area shape="rect" coords="2,-1,79,99" href="../index.htm"><area shape="rect" coords="84,1,157,108" href="../perlnut/index.htm"><area shape="rect" coords="162,2,248,125" href="../prog/index.htm"><area shape="rect" coords="253,2,326,130" href="../advprog/index.htm"><area shape="rect" coords="332,1,407,112" href="../cookbook/index.htm"><area shape="rect" coords="414,2,523,103" href="../sysadmin/index.htm"></map><!-- END OF BODY --></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?