⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch28_02.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<html><head><title>Special Variables in Alphabetical Order (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 Variables in Alphabetical Order"><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="ch28_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch28_01.htm">Chapter 28: Special Names</a></td><td align="right" valign="top" width="172"><a href="ch29_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">28.2. Special Variables in Alphabetical Order</h2><p>We've alphabetized these entries according to the long variable name.If you don't know the long name of a variable, you can find it inthe previous section.  (Variables without alphabetical names are sorted to the front.)</p><p>So that we don't have to keep repeating ourselves, each variabledescription starts with one or more of these annotations:</p><a name="perl3-tab-specvar"></a><table border="1"><tr><th>Annotation</th><th>Meaning</th></tr><tr><td>XXX</td><td><p>Deprecated, <em class="emphasis">do not use</em> in anything new.</p></td></tr><tr><td>NOT</td><td><p>Not Officially There (internal use only).</p></td></tr><tr><td>ALL</td><td><p>Truly global, shared by all packages.</p></td></tr><tr><td>PKG</td><td>Package global; each package can have its own.</td></tr><tr><td>FHA</td><td><p>Filehandle attribute; one per I/O object.</p></td></tr><tr><td>DYN</td><td>Dynamically scoped automatically (implies ALL).</td></tr><tr><td>LEX</td><td><p>Lexically scoped at compile time.</p></td></tr><tr><td>RO</td><td><p>Read only; raises an exception if you modify.</p></td></tr></table><p>When more than one variable name or symbol is listed, only the shortone is available by default.  Using the <tt class="literal">English</tt> module makes thelonger synonyms available to the current package, and only tothe current package, even if the variable is marked [ALL].</p><p>Entries of the form <em class="replaceable">method HANDLE EXPR</em> show object-orientedinterfaces to the per-filehandle variables provided by the<tt class="literal">FileHandle</tt> and various <tt class="literal">IO::</tt> modules.  (You may also use the <em class="replaceable">HANDLE</em><tt class="literal">-&gt;</tt><em class="replaceable">method</em><tt class="literal">(</tt><em class="replaceable">EXPR</em><tt class="literal">)</tt> notation if you prefer.) These let youavoid having to call <tt class="literal">select</tt> to change the default output handlebefore examining or changing that variable.  Each such method returnsthe old value of the <tt class="literal">FileHandle</tt> attribute; a new value is set ifthe <em class="replaceable">EXPR</em> argument is supplied.  If not supplied, most of the methodsdo nothing to the current value, except for <tt class="literal">autoflush</tt>, which assumesan argument of <tt class="literal">1</tt>, just to be different.</p><dl><dt><b><tt class="literal">_</tt> (underline)</b></dt><dd><p><a name="INDEX-4388"></a></p><p>[ALL] This is the special filehandle used to cache the informationfrom the last successful <tt class="literal">stat</tt>, <tt class="literal">lstat</tt>, or file test operator (like <tt class="literal">-w $file</tt>or <tt class="literal">-d $file</tt>).</p></dd><dt><b><tt class="literal">$</tt><em class="replaceable">digits</em></b></dt><dd><p><a name="INDEX-4389"></a><a name="INDEX-4390"></a><a name="INDEX-4391"></a>[DYN,RO] The numbered variables <tt class="literal">$1</tt>,<tt class="literal">$2</tt>, and so on (up just as high as youwant)<a href="#FOOTNOTE-1">[1]</a> contain the text that ismatched by the corresponding set of parentheses in the last matchedpattern within the currently active dynamic scope.  (Mnemonic: like<tt class="literal">\</tt><em class="replaceable">digits</em>.)</p><blockquote class="footnote"><a name="FOOTNOTE-1"></a><p>[1] Although many regular expression engines only supportup to nine backreferences, Perl has no such limit, so if you go aroundwriting <tt class="literal">$768</tt>, Perl won't mind, although maintainersof your code might if you actually use that many parentheses in yourregular expressions.</p></blockquote></dd><dt><b><tt class="literal">$[</tt></b></dt><dd><p><a name="INDEX-4392"></a><a name="INDEX-4393"></a><a name="INDEX-4394"></a><a name="INDEX-4395"></a>[XXX,LEX] The index of the first element in an array and of the firstcharacter in a substring.  Default is 0, but we used to set it to 1 tomake Perl behave more like <em class="emphasis">awk</em> (or FORTRAN) whensubscripting and when evaluating the <tt class="literal">index</tt> and<tt class="literal">substr</tt> functions.  Because it was found to be sodangerous, assignment to <tt class="literal">$[</tt> is now treated as alexically scoped compiler directive and cannot influence the behaviorof any other file.  (Mnemonic: <tt class="literal">[</tt> beginssubscripts.)</p></dd><dt><b><tt class="literal">$#</tt></b></dt><dd><p><a name="INDEX-4396"></a>[XXX,ALL] Don't use this; use <tt class="literal">printf</tt> instead.<tt class="literal">$#</tt> contains the output format for printed numbers,in a half-hearted attempt to emulate<em class="emphasis">awk</em>'s <tt class="literal">OFMT</tt> variable.(Mnemonic: <tt class="literal">#</tt> is the number sign, but if you'resharp, you'll just forget it so you don't make a hash of your programand get pounded for it.)</p></dd><dt><b><tt class="literal">$*</tt></b></dt><dd><p><a name="INDEX-4397"></a>[XXX,ALL] Wow, three deprecated variables in a row!  This one can (butshouldn't) be set to true to get Perl to assume <tt class="literal">/m</tt> on every patternmatch that doesn't have an explicit <tt class="literal">/s</tt>.  (Mnemonic: <tt class="literal">*</tt> matchesmultiple things.)</p></dd><dt><b><tt class="literal">$a</tt></b></dt><dd><p><a name="INDEX-4398"></a><a name="INDEX-4399"></a>[PKG] This variable is used by the <tt class="literal">sort</tt> function to hold the firstof each pair of values to be compared (<tt class="literal">$b</tt> is the second of eachpair).  The package for <tt class="literal">$a</tt> is the same one that the <tt class="literal">sort</tt> operatorwas compiled in, which is not necessarily the same as the one itscomparison function was compiled into.  This variable is implicitlylocalized within the <tt class="literal">sort</tt> comparison block.  Because it is a global,it is exempt from <tt class="literal">use strict</tt> complaints.  Because it is an alias forthe actual array value, you might think you can modify it, but youshouldn't.  See the <tt class="literal">sort</tt> function.</p></dd><dt><b><tt class="literal">$ACCUMULATOR</tt></b></dt><dt><b><tt class="literal">$^A</tt></b></dt><dd><a name="INDEX-4400"></a><a name="INDEX-4401"></a><p>[ALL] The current value of the <tt class="literal">write</tt> accumulatorfor <tt class="literal">format</tt> lines.  A format contains<tt class="literal">formline</tt> commands that put their result into<tt class="literal">$^A</tt>.  After calling its format,<tt class="literal">write</tt> prints out the contents of<tt class="literal">$^A</tt> and empties it.  So you never actually see thecontents of <tt class="literal">$^A</tt> unless you call<tt class="literal">formline</tt> yourself and then look at it.  See the<tt class="literal">formline</tt> function.</p></dd><dt><b><tt class="literal">$ARG</tt></b></dt><dt><b><tt class="literal">$_</tt></b></dt><dd><p><a name="INDEX-4402"></a><a name="INDEX-4403"></a><a name="INDEX-4404"></a>[ALL] The default input and pattern-search space. These pairs areequivalent:<blockquote><pre class="programlisting">while (&lt;&gt;) {...}    # equivalent only in unadorned while testwhile (defined($_ = &lt;&gt;)) {...}chompchomp($_)/^Subject:/$_ =~ /^Subject:/tr/a-z/A-Z/$_ =~ tr/a-z/A-Z/</pre></blockquote>Here are the places where Perl will assume <tt class="literal">$_</tt> if you don't specify something to operate on:</p></dd><dt><b><tt class="literal">@ARG</tt></b></dt><dt><b><tt class="literal">@_</tt></b></dt><dd><p><a name="INDEX-4405"></a><a name="INDEX-4406"></a><a name="INDEX-4407"></a><a name="INDEX-4408"></a><a name="INDEX-4409"></a>[ALL] Within a subroutine, this array holds the argument list passed tothat subroutine.  See <a href="ch06_01.htm">Chapter 6, "Subroutines"</a>.  A <tt class="literal">split</tt> in scalar context splits to this array, but this usage is deprecated.</p></dd><dt><b><tt class="literal">ARGV</tt></b></dt><dd><p><a name="INDEX-4410"></a>[ALL] The special filehandle that iterates over command-line filenames in <tt class="literal">@ARGV</tt>.  Usually written as the null filehandlein the angle operator: <tt class="literal">&lt;&gt;</tt>.</p></dd><dt><b><tt class="literal">$ARGV</tt></b></dt><dd><p><a name="INDEX-4411"></a>[ALL] Contains the name of the current file when reading from the <tt class="literal">ARGV</tt>handle using the <tt class="literal">&lt;&gt;</tt> or <tt class="literal">readline</tt> operators.</p></dd><dt><b><tt class="literal">@ARGV</tt></b></dt><dd><p><a name="INDEX-4412"></a>[ALL] The array containing the command-line arguments intended for thescript.  Note that <tt class="literal">$#ARGV</tt> is generally the number of argumentsminus one, since <tt class="literal">$ARGV[0]</tt> is the first argument, not the commandname; use <tt class="literal">scalar @ARGV</tt> for the number of program arguments.  See<tt class="literal">$0</tt> for the program name.</p></dd><dt><b><tt class="literal">ARGVOUT</tt></b></dt><dd><p><a name="INDEX-4413"></a>[ALL] The special filehandle is used while processing the <tt class="literal">ARGV</tt>

⌨️ 快捷键说明

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