📄 ch03_02.htm
字号:
<html><head><title>Command-Line Options (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><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" /><td align="right" valign="top" width="228"><a href="ch03_03.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h2 class="sect1">3.2. Command-Line Options</h2><p><a name="INDEX-154" /><a name="INDEX-155" /><a name="INDEX-156" /><a name="INDEX-157" />Perl expects any command-line options,also known as <em class="emphasis">switches</em> or<em class="emphasis">flags</em><a name="INDEX-158" />,to come first on the command line. The next item is usually the nameof the script, followed by any additional arguments (often filenames)to be passed into the script. Some of these additional arguments maybe switches, but if so, they must be processed by the script, sincePerl gives up parsing switches as soon as it sees either a non-switchitem or the special <tt class="literal">--</tt> switch that terminatesswitch processing.</p><p>A single-character switch with no argument may be combined (bundled)with the switch that follows it, if any. For example:</p><blockquote><pre class="code">#!/usr/bin/perl -spi.bak</pre></blockquote><p>is the same as:</p><blockquote><pre class="code">#!/usr/bin/perl -s -p -i.bak</pre></blockquote><p>Perl recognizes the <a name="INDEX-159" />switcheslisted in <a href="ch03_02.htm#perlnut2-CHP-3-TABLE-1">Table 3-1</a>.</p><a name="perlnut2-CHP-3-TABLE-1" /><h4 class="objtitle">Table 3-1. Perl switches </h4><table border="1" cellpadding="3"><tr><th><p>Switch</p></th><th><p>Function</p></th></tr><tr><td><p> <em class="emphasis">--</em> </p></td><td><p>Terminates switch processing, even if the next argument starts with aminus. It has no other effect.</p></td></tr><tr><td><p><em class="emphasis">-0</em>[<em class="emphasis">octnum</em>]</p></td><td><p>Specifies the record separator (<tt class="literal">$/</tt>) as an octalnumber. If <em class="emphasis">octnum</em> is not present, the nullcharacter is the separator. Other switches may precede or follow theoctal number.</p></td></tr><tr><td><p><em class="emphasis">-a</em></p></td><td><p>Turns on autosplit mode when used with <em class="emphasis">-n</em> or<em class="emphasis">-p</em>. An implicit <tt class="literal">split</tt> of the<tt class="literal">@F</tt> array is inserted as the first command insidethe implicit <tt class="literal">while</tt> loop produced by<em class="emphasis">-n</em> or <em class="emphasis">-p</em>. The default fielddelimiter is whitespace; a different field delimiter may be specifiedusing <em class="emphasis">-F</em>.</p></td></tr><tr><td><p><em class="emphasis">-c</em></p></td><td><p>Causes Perl to check the syntax of the script and exit withoutexecuting it. More or less equivalent to having<tt class="literal">exit(0)</tt> as the first statement in your program.</p></td></tr><tr><td><p><em class="emphasis">-d</em></p></td><td><p>Runs the script under the Perl debugger. See <a href="ch06_01.htm">Chapter 6, "Debugging"</a>. </p></td></tr><tr><td><p><em class="emphasis">-d:foo</em></p></td><td><p>Runs the script under the control of a debugging or tracing moduleinstalled in the Perl library as Devel::<em class="emphasis">foo</em>. Forexample, <em class="emphasis">-d:DProf</em> executes the script using theDevel::DProf profiler. See also the section on DProf in <a href="ch06_01.htm">Chapter 6, "Debugging"</a>. </p></td></tr><tr><td><p><em class="emphasis">-Dnumber</em></p> <p><em class="emphasis">-Dlist</em></p></td><td><p>Sets debugging flags. (This works only if debugging was compiled intothe version of Perl you are running.) You may specify either a numberthat is the sum of the bits you want, or a list of letters. To watchhow Perl executes your script, for instance, use<em class="emphasis">-D14</em> or <em class="emphasis">-Dslt</em>. Anotheruseful value is <em class="emphasis">-D1024</em>(<em class="emphasis">-Dx</em>), which lists your compiled syntax tree.And <em class="emphasis">-D512</em> (<em class="emphasis">-Dr</em>) displayscompiled regular expressions. The numeric value of the flags isavailable internally as the special variable <tt class="literal">$^D</tt>.Here are the assigned bit values:</p></td></tr><tr><td> </td><td><p><b class="emphasis-bold">Bit</b></p></td><td><p><b class="emphasis-bold">Letter</b></p></td><td><p><b class="emphasis-bold">Meaning</b></p></td></tr><tr><td> </td><td><p>1</p></td><td><p><tt class="literal">p</tt></p></td><td><p>Tokenizing and parsing</p></td><td> </td></tr><tr><td> </td><td><p>2</p></td><td><p><tt class="literal">s</tt></p></td><td><p>Stack snapshots</p></td></tr><tr><td> </td><td><p>4</p></td><td><p><tt class="literal">l</tt></p></td><td><p>Label stack processing</p></td></tr><tr><td> </td><td><p>8</p></td><td><p><tt class="literal">t</tt></p></td><td><p>Trace execution</p></td></tr><tr><td> </td><td><p>16</p></td><td><p><tt class="literal">o</tt></p></td><td><p>Object method lookup</p></td></tr><tr><td> </td><td><p>32</p></td><td><p><tt class="literal">c</tt></p></td><td><p>String/numeric conversions</p></td></tr><tr><td> </td><td><p>64</p></td><td><p><tt class="literal">P</tt></p></td><td><p>Print preprocessor command for <em class="emphasis">-P</em></p></td></tr><tr><td> </td><td><p>128</p></td><td><p><tt class="literal">m</tt></p></td><td><p>Memory allocation</p></td></tr><tr><td> </td><td><p>256</p></td><td><p><tt class="literal">f</tt></p></td><td><p>Format processing</p></td></tr><tr><td> </td><td><p>512</p></td><td><p><tt class="literal">r</tt></p></td><td><p>Regular expression processing</p></td></tr><tr><td> </td><td><p>1,024</p></td><td><p><tt class="literal">x</tt></p></td><td><p>Syntax tree dump</p></td></tr><tr><td> </td><td><p>2,048</p></td><td><p><tt class="literal">u</tt></p></td><td><p>Tainting checks</p></td></tr><tr><td> </td><td><p>4,096</p></td><td><p><tt class="literal">L</tt></p></td><td><p>Memory leaks (not supported anymore)</p></td></tr><tr><td> </td><td><p>8,192</p></td><td><p><tt class="literal">H</tt></p></td><td><p>Hash dump; usurps <em class="emphasis">values</em></p></td></tr><tr><td> </td><td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -