📄 ch28_02.htm
字号:
command-line switch is given. If the<span class="option">-a</span> option is not used, this array has no specialmeaning. (This array is actually only <tt class="literal">@main::F</tt>,and not in all packages at once.)</p></dd><dt><b><tt class="literal">%FIELDS</tt></b></dt><dd><p><a name="INDEX-4464"></a>[NOT,PKG] This hash is for internal use by the <tt class="literal">use fields</tt> pragma todetermine the current legal fields in an object hash. See <tt class="literal">usefields</tt>, <tt class="literal">use base</tt>, and "Field Declarations with use fields" in<a href="ch12_01.htm">Chapter 12, "Objects"</a>.</p></dd><dt><b><tt class="literal">format_formfeed</tt> <em class="replaceable">HANDLE EXPR</em></b></dt><dt><b><tt class="literal">$FORMAT_FORMFEED</tt></b></dt><dt><b><tt class="literal">$^L</tt></b></dt><dd><p><a name="INDEX-4465"></a><a name="INDEX-4466"></a><a name="INDEX-4467"></a>[ALL] What a <tt class="literal">write</tt> function implicitly outputs to perform a form feed beforeit emits a top of form header. Default is <tt class="literal">"\f"</tt>.</p></dd><dt><b><tt class="literal">format_lines_left</tt> <em class="replaceable">HANDLE EXPR</em></b></dt><dt><b><tt class="literal">$FORMAT_LINES_LEFT</tt></b></dt><dt><b><tt class="literal">$-</tt></b></dt><dd><p><a name="INDEX-4468"></a><a name="INDEX-4469"></a>[FHA] The number of lines left on the page of the currently selected outputhandle, for use with the <tt class="literal">format</tt> declaration and the<tt class="literal">write</tt> function. (Mnemonic: <tt class="literal">lines_on_page- lines_printed</tt>.)</p></dd><dt><b><tt class="literal">format_lines_per_page</tt> <em class="replaceable">HANDLE EXPR</em></b></dt><dt><b><tt class="literal">$FORMAT_LINES_PER_PAGE</tt></b></dt><dt><b><tt class="literal">$=</tt></b></dt><dd><p><a name="INDEX-4470"></a><a name="INDEX-4471"></a>[FHA] The current page length (printable lines) of the currently selectedoutput handle, for use with <tt class="literal">format</tt> and <tt class="literal">write</tt>. Default is 60.(Mnemonic: <tt class="literal">=</tt> has horizontal lines.)</p></dd><dt><b><tt class="literal">format_line_break_characters</tt> <em class="replaceable">HANDLE EXPR</em></b></dt><dt><b><tt class="literal">$FORMAT_LINE_BREAK_CHARACTERS</tt></b></dt><dt><b><tt class="literal">$:</tt></b></dt><dd><p><a name="INDEX-4472"></a><a name="INDEX-4473"></a><a name="INDEX-4474"></a><a name="INDEX-4475"></a>[ALL] The current set of characters after which a string may be brokento fill continuation fields (starting with <tt class="literal">^</tt>) in aformat. Default is <tt class="literal">" \n-"</tt>, to break on whitespaceor hyphens. (Mnemonic: a colon is a technical word meaning part of aline in poetry. Now you just have to remember the mnemonic...)</p></dd><dt><b><tt class="literal">format_name</tt> <em class="replaceable">HANDLE EXPR</em></b></dt><dt><b><tt class="literal">$FORMAT_NAME</tt></b></dt><dt><b><tt class="literal">$~</tt></b></dt><dd><p><a name="INDEX-4476"></a><a name="INDEX-4477"></a>[FHA] The name of the current report format for the currently selected outputhandle. Default is the filehandle's name. (Mnemonic: takes a turnafter <tt class="literal">$^</tt>.)</p></dd><dt><b><tt class="literal">format_page_number</tt> <em class="replaceable">HANDLE EXPR</em></b></dt><dt><b><tt class="literal">$FORMAT_PAGE_NUMBER</tt></b></dt><dt><b><tt class="literal">$%</tt></b></dt><dd><p><a name="INDEX-4478"></a><a name="INDEX-4479"></a><a name="INDEX-4480"></a><a name="INDEX-4481"></a><a name="INDEX-4482"></a><a name="INDEX-4483"></a>[FHA] The current page number of the currently selected output handle,for use with <tt class="literal">format</tt> and <tt class="literal">write</tt>.(Mnemonic: <tt class="literal">%</tt> is the page number register in <em class="emphasis">troff</em>(1). What, you don'tknow what <em class="emphasis">troff</em> is?)</p></dd><dt><b><tt class="literal">format_top_name</tt> <em class="replaceable">HANDLE EXPR</em></b></dt><dt><b><tt class="literal">$FORMAT_TOP_NAME</tt></b></dt><dt><b><tt class="literal">$^</tt></b></dt><dd><p><a name="INDEX-4484"></a><a name="INDEX-4485"></a><a name="INDEX-4486"></a><a name="INDEX-4487"></a>[FHA] The name of the current top-of-page format for the currently selectedoutput handle. Default is name of the filehandle with <tt class="literal">_TOP</tt>appended. (Mnemonic: points to top of page.)</p></dd><dt><b><tt class="literal">$^H</tt></b></dt><dd><p><a name="INDEX-4488"></a><a name="INDEX-4489"></a><a name="INDEX-4490"></a></p><p>[NOT,LEX] This variable contains lexically scoped status bits (a.k.a. hints) for the Perl parser. This variable is strictly for internal useonly. Its availability, behavior, and contents are subject to changewithout notice. If you touch it, you will undoubtedly die a horribledeath of some loathsome tropical disease unknown to science. (Mnemonic: we won't give you a hint.)</p></dd><dt><b><tt class="literal">%^H</tt></b></dt><dd><p>[NOT,LEX] The <tt class="literal">%^H</tt> hash provides the same lexical scoping semanticsas <tt class="literal">$^H</tt>, making it useful for implementation of lexically scopedpragmas. Read the dire warnings listed under <tt class="literal">$^H</tt>, and then add tothem the fact that this variable is still experimental.</p></dd><dt><b><tt class="literal">%INC</tt></b></dt><dd><p><a name="INDEX-4491"></a><a name="INDEX-4492"></a><a name="INDEX-4493"></a></p><p>[ALL] The hash containing entries for the filename of each Perl fileloaded via <tt class="literal">do</tt><em class="replaceable">FILE</em>,<tt class="literal">require</tt>, or <tt class="literal">use</tt>. The key is thefilename you specified, and the value is the location of the fileactually found. The <tt class="literal">require</tt> operator uses thisarray to determine whether a given file has already been loaded. Forexample:<blockquote><pre class="programlisting">% <tt class="userinput"><b>perl -MLWP::Simple -le 'print $INC{"LWP/Simple.pm"}'</b></tt>/opt/perl/5.6.0/lib/site_perl/LWP/Simple.pm</pre></blockquote></p></dd><dt><b><tt class="literal">@INC</tt></b></dt><dd><p><a name="INDEX-4494"></a><a name="INDEX-4495"></a><a name="INDEX-4496"></a>[ALL] The array containing the list of directories where Perl modulesmay be found by <tt class="literal">do</tt><em class="replaceable">FILE</em>,<tt class="literal">require</tt>, or <tt class="literal">use</tt>. It initiallyconsists of the arguments to any <span class="option">-I</span> command-lineswitches and directories in the <tt class="literal">PERL5LIB</tt>environment variable, followed by the default Perl libraries, such as:<blockquote><pre class="programlisting">/usr/local/lib/perl5/5.6.0/sun4-solaris/usr/local/lib/perl5/5.6.0/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris/usr/local/lib/perl5/site_perl/5.6.0/usr/local/lib/perl5/site_perl/5.00552/sun4-solaris/usr/local/lib/perl5/site_perl/5.00552/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/usr/local/lib/perl5/site_perl/5.005/usr/local/lib/perl5/site_perl</pre></blockquote>followed by "<tt class="literal">.</tt>", to represent the currentdirectory. If you need to modify this list from within your program,try the <tt class="literal">use lib</tt> pragma, which not only modifies thevariable at compile time, but also adds in any relatedarchitecture-dependent directories (such as those that contain theshared libraries used by XS modules):<blockquote><pre class="programlisting">use lib "/mypath/libdir/";use SomeMod;</pre></blockquote></p></dd><dt><b><tt class="literal">$INPLACE_EDIT</tt></b></dt><dt><b><tt class="literal">$^I</tt></b></dt><dd><p><a name="INDEX-4497"></a><a name="INDEX-4498"></a><a name="INDEX-4499"></a></p><p>[ALL] The current value of the inplace-edit extension. Use <tt class="literal">undef</tt> todisable inplace editing. You can use this from within your programto get the same behavior as the <span class="option">-i</span> switch provides. For example,to do the equivalent of this command:<blockquote><pre class="programlisting">% <tt class="userinput"><b>perl -i.orig -pe 's/foo/bar/g' *.c</b></tt></pre></blockquote>you can use the following equivalent code in your program:<blockquote><pre class="programlisting">local $^I = '.orig';local @ARGV = glob("*.c");while (<>) { s/foo/bar/g; print;}</pre></blockquote>(Mnemonic: value of the <tt class="userinput"><b>-i</b></tt> switch.)</p></dd><dt><b><tt class="literal">$INPUT_LINE_NUMBER</tt></b></dt><dt><b><tt class="literal">$NR</tt></b></dt><dt><b><tt class="literal">$.</tt></b></dt><dd><p><a name="INDEX-4500"></a><a name="INDEX-4501"></a><a name="INDEX-4502"></a>[ALL] The current record number (usually line number) for the lastfilehandle you read from (or called <tt class="literal">seek</tt> or<tt class="literal">tell</tt> on). The value may be different from theactual physical line number in the file, depending on what notion of"line" is in effect--see <tt class="literal">$/</tt>(<tt class="literal">$INPUT_RECORD_SEPARATOR</tt>) on how to affect that.An explicit close on a filehandle resets the line number. Because<tt class="literal"><></tt> never does an explicit close, line numbersincrease across <tt class="literal">ARGV</tt> files (but see examples under<tt class="literal">eof</tt>). Localizing <tt class="literal">$.</tt> alsolocalizes Perl's notion of "the last read filehandle". (Mnemonic:many programs use "<tt class="literal">.</tt>" to mean the current linenumber.)</p></dd><dt><b><tt class="literal">$INPUT_RECORD_SEPARATOR</tt></b></dt><dt><b><tt class="literal">$RS</tt></b></dt><dt><b><tt class="literal">$/</tt></b></dt><dd><p><a name="INDEX-4503"></a><a name="INDEX-4504"></a><a name="INDEX-4505"></a><a name="INDEX-4506"></a>[ALL] The input record separator, newline by default, which isconsulted by the <tt class="literal">readline</tt> function, the<tt class="literal"><FH></tt> operator, and the<tt class="literal">chomp</tt> function. It works like<em class="emphasis">awk</em>'s <tt class="literal">RS</tt> variable,and, if set to the null string, treats one or more blank lines as arecord terminator. (But a blank line must contain no hidden spaces ortabs.) You may set it to a multicharacter string to match amulticharacter terminator, but you may not set it to apattern--<em class="emphasis">awk</em> has to be better at something.</p><p>Note that setting <tt class="literal">$/</tt> to <tt class="literal">"\n\n"</tt>means something slightly different than setting it to<tt class="literal">""</tt>, if the file contains consecutive blank lines.Setting it to <tt class="literal">""</tt> will treat two or<em class="emphasis">more</em> consecutive blank lines as a single blankline. Setting it to <tt class="literal">"\n\n"</tt> means Perl will blindlyassume that a third newline belongs to the next paragraph.</p><p>Entirely undefining <tt class="literal">$/</tt> makes the next line input operationslurp in the remainder of the file as one scalar value:<blockquote><pre class="programlisting">undef $/; # enable whole-file mode$_ = <FH>; # whole file now heres/\n[ \t]+/ /g; # fold indented lines</pre></blockquote>If you're using the <tt class="literal">while (<>)</tt> construct toaccess <tt class="literal">ARGV</tt> handle while <tt class="literal">$/</tt> is undefined, eachread gets the next file:<blockquote><pre class="programlisting">undef $/;while (<>) { # $_ has the whole next file in it ...}</pre></blockquote><a name="INDEX-4507"></a></p><p>Although we used <tt class="literal">undef</tt> above, it's safer to undefine <tt class="literal">$/</tt> using <tt class="literal">local</tt>:</p><blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -