📄 ch03_02.htm
字号:
<p>16,384</p></td><td><p><tt class="literal">X</tt></p></td><td><p>Scratchpad allocation</p></td></tr><tr><td> </td><td><p>32,768</p></td><td><p><tt class="literal">D</tt></p></td><td><p>Cleaning up</p></td></tr><tr><td><p><em class="emphasis">-e commandline</em></p></td><td><p>May be used to enter one or more lines of script. If<em class="emphasis">-e</em> is used, Perl does not look for the name of ascript in the argument list. Multiple <em class="emphasis">-e</em>commands may be given to build up a multiline script. (Make sure touse semicolons where you would in a normal program.)</p></td></tr><tr><td><p><em class="emphasis">-Fpattern</em></p></td><td><p>Specifies the pattern to split on if <em class="emphasis">-a</em> is alsoin effect. The pattern may be surrounded by <em class="emphasis">//</em>,<tt class="literal">''</tt>, or <tt class="literal">""</tt>; otherwise it is putin single quotes. As of Perl 5.8, the <em class="emphasis">-F</em> optionis recognized on the <tt class="literal">#!</tt> line.</p></td></tr><tr><td><p> <em class="emphasis">-h</em></p></td><td><p>Prints a summary of Perl's command-line options.</p></td></tr><tr><td><p><em class="emphasis">-i</em>[<em class="emphasis">extension</em>]</p></td><td><p>Specifies that files processed by the <tt class="literal"><></tt>construct are to be edited in-place. Perl does this by renaming theinput file, opening the output file by the original name, andselecting that output file as the default for<tt class="literal">print</tt> statements. The extension, if supplied, isadded to the name of the old file to make a backup copy. If noextension is supplied, no backup is made.</p></td></tr><tr><td><p><em class="emphasis">-I</em>[<em class="emphasis">directory]</em></p></td><td><p>Directories specified by <em class="emphasis">-I</em> are prepended to<tt class="literal">@INC</tt>, which holds the search path for modules. If<em class="emphasis">-P</em> is also specified, to invoke the Cpreprocessor, <em class="emphasis">-I</em> tells the preprocessor where tosearch for include files. By default, it searches<em class="emphasis">/usr/include</em> and<em class="emphasis">/usr/lib/perl</em>.</p></td></tr><tr><td><p><em class="emphasis">-l</em>[<em class="emphasis">octnum</em>]</p></td><td><p>Enables automatic line-end processing. This switch has two effects.First, when it's used with <em class="emphasis">-n</em>or <em class="emphasis">-p</em>, it causes the line terminator to beautomatically <tt class="literal">chomp</tt> ed. Second, it sets<tt class="literal">$\</tt> to the value of <em class="emphasis">octnum</em> soany print statements will have a line terminator of ASCII value<em class="emphasis">octnum</em> added back on. If<em class="emphasis">octnum</em> is omitted, <tt class="literal">$\</tt> is setto the current value of <tt class="literal">$/</tt>, which is typically anewline. So, to trim lines to 80 columns, say this:</p> <blockquote><pre class="code">perl -lpe 'substr($_, 80) = ""'</pre></blockquote></td></tr><tr><td><p><em class="emphasis">-m</em>[<em class="emphasis">-</em>]<em class="emphasis">module</em></p> <p><em class="emphasis">-M</em>[<em class="emphasis">-</em>]<em class="emphasis">module</em></p> <p><em class="emphasis">-M</em>[<em class="emphasis">-</em>]'<em class="emphasis">module...</em>'</p> <p><em class="emphasis">-</em>[<em class="replaceable"><tt>mM</em>][<em class="emphasis">-</em>]<em class="emphasis">modulearg</em>[<em class="emphasis">,arg</em>]<em class="emphasis">...</tt></em></p> <p><em class="emphasis">-mmodule</em></p></td><td><p>Executes <tt class="literal">use</tt> <em class="emphasis">module</em> beforeexecuting your script.</p></td></tr><tr><td><p><em class="emphasis">-Mmodule</em></p></td><td><p>Executes <tt class="literal">use</tt> <em class="emphasis">module</em> beforeexecuting your script. The command is formed by interpolation, so youcan use quotes to add extra code after the module name—forexample, <em class="emphasis">-M'module qw(foobar)</em>'. If the first character after the<em class="emphasis">-M</em> or <em class="emphasis">-m</em> is a minus(<em class="emphasis">-</em>), then the <tt class="literal">use</tt> is replacedwith <tt class="literal">no</tt>.</p> <p>You can also say <em class="emphasis">-m module=foo,bar</em> or<em class="emphasis">-Mmodule= foo,bar</em> as a shortcut for<em class="emphasis">-M'module qw(foobar)</em>'. This avoids the need to use quoteswhen importing symbols. The actual code generated by<em class="emphasis">-Mmodule=foo,bar</em> is:</p> <blockquote><pre class="code">use module split(/,/, q{foo,bar})</pre></blockquote> <p>The <em class="emphasis">=</em> form removes the distinction between<em class="emphasis">-m</em> and <em class="emphasis">-M</em>.</p></td></tr><tr><td><p><em class="emphasis">-n</em></p></td><td><p>Causes Perl to assume the following loop around your script, whichmakes it iterate over filename arguments:</p> <blockquote><pre class="code">LINE:while (<>) { ... # Your script goes here</pre></blockquote> <p>By default, the lines are not printed. (See <em class="emphasis">-p</em>to have lines printed.) BEGIN and END blocks may be used to capturecontrol before or after the implicit loop.</p></td></tr><tr><td><p><em class="emphasis">-p</em></p></td><td><p>Causes Perl to assume the following loop around your script, whichmakes it iterate over filename arguments:</p> <blockquote><pre class="code">LINE:while (<>) { ... # Your script goes here} continue { print;</pre></blockquote> <p>The lines are printed automatically. To suppress printing, use the<em class="emphasis">-n</em> switch. If both are specified, the<em class="emphasis">-p</em> switch overrides <em class="emphasis">-n</em>.BEGIN and END blocks may be used to capture control before or afterthe implicit loop.</p></td></tr><tr><td><p><em class="emphasis">-P</em></p></td><td><p>Causes your script to run through the C preprocessor beforecompilation by Perl. (Since both comments and<em class="emphasis">cpp</em> directives begin with the<tt class="literal">#</tt> character, you should avoid starting commentswith any words recognized by the C preprocessor, such as<tt class="literal">if</tt>, <tt class="literal">else</tt>, or<tt class="literal">define</tt>.)</p></td></tr><tr><td><p><em class="emphasis">-s</em></p></td><td><p>Enables some rudimentary parsing of switches on the command lineafter the script name but before any filename arguments or the <em class="emphasis">--</em> switch terminator. Any switch foundthere is removed from <tt class="literal">@ARGV</tt>, and a variable of thesame name as the switch is set in the Perl script. No switch bundlingis allowed, since multicharacter switches are allowed. As of Perl5.8, <em class="emphasis">-s</em> is recognized on the<tt class="literal">#!</tt> line.</p></td></tr><tr><td><p><em class="emphasis">-S</em></p></td><td><p>Makes Perl use the PATH environment variable to search for the script(unless the name of the script starts with a slash). Typically, thisis used to emulate <tt class="literal">#!</tt> startup on machines thatdon't support <tt class="literal">#!</tt>.</p></td></tr><tr><td><p><em class="emphasis">-t</em></p></td><td><p>Forces "taint" checks to be turnedon, but warning will be issued instead of fatal errors. Warnings canbe controlled with <tt class="literal">no warnings qw (taint)</tt>.Designed for use in development only; <em class="emphasis">-T</em> ispreferred for production code. New in 5.8.</p></td></tr><tr><td><p><em class="emphasis">-T</em></p></td><td><p>Forces "taint" checks to be turnedon. Ordinarily, these checks are done only when running setuid orsetgid. It's a good idea to turn them on explicitlyfor programs run on another user's behalf, such asCGI programs.</p></td></tr><tr><td><p><em class="emphasis">-u</em></p></td><td><p>Causes Perl to dump core after compiling your script. You can takethis core dump and turn it into an executable file by using the<em class="emphasis">undump</em> program (not supplied). This speedsstartup at the expense of some disk space (which you can minimize bystripping the executable). If you want to execute a portion of yourscript before dumping, use Perl's<tt class="literal">dump</tt> operator instead. Note: availability of<em class="emphasis">undump</em> is platform-specific; it may not beavailable for a specific port of Perl.</p></td></tr><tr><td><p><em class="emphasis">-U</em></p></td><td><p>Allows Perl to do unsafe operations. Currently, the only"unsafe"operations are theunlinking of directories while running as superuser and runningsetuid programs with fatal taint checks turned into warnings.</p></td></tr><tr><td><p><em class="emphasis">-v</em></p></td><td><p>Prints the version and patch level of your Perl executable.</p></td></tr><tr><td><p><em class="emphasis">-V</em></p></td><td><p>Prints a summary of the major Perl configuration values and thecurrent value of <tt class="literal">@INC</tt>.</p></td></tr><tr><td><p><em class="emphasis">-V:name</em></p></td><td><p>Prints the value of the named configuration variable to STDOUT.</p></td></tr><tr><td><p><em class="emphasis">-w</em></p></td><td><p>Prints warnings about identifiers that are mentioned only once andscalar variables that are used before being set. Also warns aboutredefined subroutines and references to undefined filehandles or tofilehandles opened as read-only that you are attempting to write on.Warns you if you use a non-number as though it was a number, if youuse an array as though it was a scalar, if your subroutines recursemore than 100 levels deep, etc.</p></td></tr><tr><td><p><em class="emphasis">-x</em>[<em class="emphasis">directory</em>]</p></td><td><p>Tells Perl to extract a script that is embedded in a message bylooking for the first line that starts with <tt class="literal">#!</tt> andcontains the string "perl". Anymeaningful switches on that line after the word"perl" are applied. If a directoryname is specified, Perl switches to that directory before running thescript. The script must be terminated with <tt class="literal">_ _END__</tt> or <tt class="literal">_ _DATA_ _</tt> if there is trailingtext to be ignored. (The script can process any or all of thetrailing text via the DATA filehandle if desired.)<a name="INDEX-160" /></p></td></tr></table><p><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch03_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch03_03.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">3. The Perl Executable</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">3.3. Environment Variables</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright © 2002</a> O'Reilly & Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -