📄 ch28_02.htm
字号:
handle under the <span class="option">-i</span> switch or the <tt class="literal">$^I</tt> variable. See the<span class="option">-i</span> switch in <a href="ch19_01.htm">Chapter 19, "The Command-Line Interface"</a>.</p></dd><dt><b><tt class="literal">$b</tt></b></dt><dd><p>[PKG] The variable, companion to <tt class="literal">$a</tt>, used in <tt class="literal">sort</tt>comparisons. See <tt class="literal">$a</tt> and the <tt class="literal">sort</tt> function for details.</p></dd><dt><b><tt class="literal">$BASETIME</tt></b></dt><dt><b><tt class="literal">$^T</tt></b></dt><dd><p><a name="INDEX-4414"></a><a name="INDEX-4415"></a><a name="INDEX-4416"></a><a name="INDEX-4417"></a>[ALL] The time at which the script began running, in seconds since the epoch(the beginning of 1970, for Unix systems). The values returned by the<tt class="literal">-M</tt>, <tt class="literal">-A</tt>, and <tt class="literal">-C</tt> file tests are relative to this moment.</p></dd><dt><b><tt class="literal">$CHILD_ERROR</tt></b></dt><dt><b><tt class="literal">$?</tt></b></dt><dd><p><a name="INDEX-4418"></a><a name="INDEX-4419"></a><a name="INDEX-4420"></a><a name="INDEX-4421"></a><a name="INDEX-4422"></a><a name="INDEX-4423"></a>[ALL] The status returned by the last pipe close, backtick(<tt class="literal">``</tt>) command, or <tt class="literal">wait</tt>,<tt class="literal">waitpid</tt>, or <tt class="literal">system</tt> functions.Note that this is not just the simple exit code, but the entire 16-bitstatus word returned by the underlying<em class="emphasis">wait</em>(2) or<em class="emphasis">waitpid</em>(2) syscall (or equivalent). Thus,the exit value of the subprocess is in the high byte, that is,<tt class="literal">$? >> 8</tt>; in the low byte, <tt class="literal">$? &127</tt> says which signal (if any) the process died from, while<tt class="literal">$? & 128</tt> reports whether its demise produced acore dump. (Mnemonic: similar to <tt class="literal">$?</tt> in the<em class="emphasis">sh</em> and its offspring.)</p><p>Inside an <tt class="literal">END</tt> block, <tt class="literal">$?</tt> contains the value that is going to begiven to <tt class="literal">exit</tt>. You can modify <tt class="literal">$?</tt> in an <tt class="literal">END</tt> tochange the exit status of the script.</p><p>Under VMS, the pragma <tt class="literal">use vmsish 'status'</tt> makes <tt class="literal">$?</tt> reflectthe true VMS exit status, instead of the default emulation of POSIXstatus.</p><p>If the <tt class="literal">h_errno</tt> variable is supported in C, its numeric value isreturned via <tt class="literal">$?</tt> if any of the <tt class="literal">gethost*()</tt> functions fail.</p></dd><dt><b><tt class="literal">$COMPILING</tt></b></dt><dt><b><tt class="literal">$^C</tt></b></dt><dd><p><a name="INDEX-4424"></a><a name="INDEX-4425"></a><a name="INDEX-4426"></a><a name="INDEX-4427"></a>[ALL] The current value of the internal flag associated with the<span class="option">-c</span> switch, mainly of use with<span class="option">-MO</span> and the<em class="emphasis">perlcc</em>(1) tool to let code alter itsbehavior when being compiled for code generation. For example, youmight want to <tt class="literal">AUTOLOAD</tt> at compile time instead ofusing the normal, deferred loading so that code can be generated rightaway. See <a href="ch18_01.htm">Chapter 18, "Compiling"</a>.</p></dd><dt><b><tt class="literal">DATA</tt></b></dt><dd><p><a name="INDEX-4428"></a><a name="INDEX-4429"></a><a name="INDEX-4430"></a>[PKG] This special filehandle refers to anything followingeither the <tt class="literal">__END__</tt> token or the <tt class="literal">__DATA__</tt> token in the current file.The <tt class="literal">__END__</tt> token always opens the <tt class="literal">main::DATA</tt> filehandle, and so isused in the main program. The <tt class="literal">__DATA__</tt> token opens the <tt class="literal">DATA</tt> handlein whichever package is in effect at the time, so different modules caneach have their own <tt class="literal">DATA</tt> filehandle, since they (presumably) havedifferent package names.</p></dd><dt><b><tt class="literal">$DEBUGGING</tt></b></dt><dt><b><tt class="literal">$^D</tt></b></dt><dd><p><a name="INDEX-4431"></a><a name="INDEX-4432"></a><a name="INDEX-4433"></a>[ALL] The current value of the internal debugging flags, set from the<span class="option">-D</span> switch on the command line; see <a href="ch19_01.htm">Chapter 19, "The Command-Line Interface"</a> for the bit values. (Mnemonic: value of the <span class="option">-D</span> switch.)</p></dd><dt><b><tt class="literal">$EFFECTIVE_GROUP_ID</tt></b></dt><dt><b><tt class="literal">$EGID</tt></b></dt><dt><b><tt class="literal">$)</tt></b></dt><dd><p><a name="INDEX-4434"></a><a name="INDEX-4435"></a><a name="INDEX-4436"></a><a name="INDEX-4437"></a>[ALL] The effective GID (group ID) of this process. If you are on amachine that supports membership in multiple groups simultaneously,<tt class="literal">$)</tt> gives a space-separated list of groups you arein. The first number is the one returned by<em class="emphasis">getegid</em>(2), and the subsequent ones by<em class="emphasis">getgroups</em>(2), one of which may be the sameas the first number.</p><p>Similarly, a value assigned to <tt class="literal">$)</tt> must also be aspace-separated list of numbers. The first number is used to set theeffective GID, and the rest (if any) are passed to the<em class="emphasis">setgroups</em>(2) syscall. To get the effectof an empty list for <tt class="literal">setgroups</tt>, just repeat the neweffective GID; for example,to force an effective GID of 5 and aneffectively empty <tt class="literal">setgroups</tt> list, say:<blockquote><pre class="programlisting">$) = "5 5";</pre></blockquote></p><p>(Mnemonic: parentheses are used to <em class="emphasis">group</em> things. The effectiveGID is the group that's <em class="emphasis">right</em> for you, if you're running setgid.) Note: <tt class="literal">$<</tt>, <tt class="literal">$></tt>, <tt class="literal">$(</tt>, and <tt class="literal">$)</tt> can only be set onmachines that support the corresponding system set-id routine.<tt class="literal">$(</tt> and <tt class="literal">$)</tt> can be swapped only on machines supporting<em class="emphasis">setregid</em>(2).</p></dd><dt><b><tt class="literal">$EFFECTIVE_USER_ID</tt></b></dt><dt><b><tt class="literal">$EUID</tt></b></dt><dt><b><tt class="literal">$></tt></b></dt><dd><p><a name="INDEX-4438"></a><a name="INDEX-4439"></a><a name="INDEX-4440"></a><a name="INDEX-4441"></a><a name="INDEX-4442"></a>[ALL] The effective UID of this process as returned by the<em class="emphasis">geteuid</em>(2) syscall. Example:<blockquote><pre class="programlisting">$< = $>; # set real to effective uid($<,$>) = ($>,$<); # swap real and effective uid</pre></blockquote>(Mnemonic: it's the UID you went <em class="emphasis">to</em>, if you'rerunning setuid.) Note: <tt class="literal">$<</tt> and<tt class="literal">$></tt> can only be swapped on machines supporting<em class="emphasis">setreuid</em>(2). And sometimes not even then.</p></dd><dt><b><tt class="literal">%ENV</tt></b></dt><dd><p><a name="INDEX-4443"></a><a name="INDEX-4444"></a><a name="INDEX-4445"></a>[ALL] The hash containing your current environment variables. Settinga value in <tt class="literal">%ENV</tt> changes the environment for both your process and child processes launched after the assignment. (It cannot changea parent process's environment on any system resembling Unix.)<blockquote><pre class="programlisting">$ENV{PATH} = "/bin:/usr/bin";$ENV{PAGER} = "less";$ENV{LESS} = "MQeicsnf"; # our favorite switches to less(1)system "man perl"; # picks up new settings</pre></blockquote>To remove something from your environment, make sure to use the <tt class="literal">delete</tt>function instead of <tt class="literal">undef</tt> on the hash value.</p><p>Note that processes running as <em class="emphasis">crontab</em>(5)entries inherit a particularly impoverished set of environmentvariables. (If your program runs fine from the command line but notunder <em class="emphasis">cron</em>, this is probably why.) Also note thatyou should set <tt class="literal">$ENV{PATH}</tt>,<tt class="literal">$ENV{SHELL}</tt>, <tt class="literal">$ENV{BASH_ENV}</tt>, and<tt class="literal">$ENV{IFS}</tt> if you are running as a setuid script.See <a href="ch23_01.htm">Chapter 23, "Security"</a>.</p></dd><dt><b><tt class="literal">$EVAL_ERROR</tt></b></dt><dt><b><tt class="literal">$@</tt></b></dt><dd><p><a name="INDEX-4446"></a><a name="INDEX-4447"></a><a name="INDEX-4448"></a><a name="INDEX-4449"></a>[ALL] The currently raised exception or the Perl syntax error messagefrom the last <tt class="literal">eval</tt> operation. (Mnemonic: where wasthe syntax error "at"?) Unlike <tt class="literal">$!</tt>(<tt class="literal">$OS_ERROR</tt>), which is set on failure but not clearedon success, <tt class="literal">$@</tt> is guaranteed to be set (to a truevalue) if the last <tt class="literal">eval</tt> had a compilation error orrun-time exception, and guaranteed to be cleared (to a false value) ifno such problem occurred.</p><p>Warning messages are not collected in this variable. Youcan, however, set up a routine to process warnings by setting<tt class="literal">$SIG{__WARN__}</tt> as described later in this section.</p><p>Note that the value of <tt class="literal">$@</tt> may be an exception object rather than a string.If so, you can still probably treat it as a string if the exception objecthas stringification overloading defined for its class. If you propagatean exception by saying:<blockquote><pre class="programlisting">die if $@;</pre></blockquote>then an exception object will call <tt class="literal">$@->PROPAGATE</tt> to see what to do.(A string exception merely adds a "propagated at" line to the string.)</p></dd><dt><b><tt class="literal">$EXCEPTIONS_BEING_CAUGHT</tt></b></dt><dt><b><tt class="literal">$^S</tt></b></dt><dd><p><a name="INDEX-4450"></a><a name="INDEX-4451"></a>[ALL] This variable reflects the current state of the interpreter,returning true if inside an <tt class="literal">eval</tt>, false otherwise. It's undefined ifparsing of the current compilation unit hasn't finished yet, which maybe the case in <tt class="literal">$SIG{__DIE__}</tt> and <tt class="literal">$SIG{__WARN__}</tt> handlers. (Mnemonic: state of <tt class="literal">eval</tt>.)</p></dd><dt><b><tt class="literal">$EXECUTABLE_NAME</tt></b></dt><dt><b><tt class="literal">$^X</tt></b></dt><dd><p><a name="INDEX-4452"></a><a name="INDEX-4453"></a><a name="INDEX-4454"></a>[ALL] The name that the <em class="emphasis">perl</em> binary itself was executed as, from C's<tt class="literal">argv[0]</tt>.</p></dd><dt><b><tt class="literal">@EXPORT</tt></b></dt><dd><p><a name="INDEX-4455"></a>[PKG] This array variable is consulted by the<tt class="literal">Exporter</tt> module's <tt class="literal">import</tt> methodto find the list of other package variables and subroutines to beexported by default when the module is <tt class="literal">use</tt>d, orwhen the <tt class="literal">:DEFAULT</tt> import tag is used. It is notexempt from <tt class="literal">use strict</tt> complaints, so it must bedeclared with <tt class="literal">our</tt> or fully qualified by packagename if you've enabled that pragma. However, all variables whosenames begin with the string "<tt class="literal">EXPORT</tt>" are exemptfrom warnings about being used only once. See <a href="ch11_01.htm">Chapter 11, "Modules"</a>.</p></dd><dt><b><tt class="literal">@EXPORT_OK</tt></b></dt><dd><p><a name="INDEX-4456"></a>[PKG] This array variable is consulted by the <tt class="literal">Exporter</tt>module's <tt class="literal">import</tt> method to determine whether a requested importis legal. It is not exempt from <tt class="literal">use strict</tt>. See <a href="ch11_01.htm">Chapter 11, "Modules"</a>.</p></dd><dt><b><tt class="literal">%EXPORT_TAGS</tt></b></dt><dd><p><a name="INDEX-4457"></a>[PKG] This hash variable is consulted by the <tt class="literal">Exporter</tt>module's <tt class="literal">import</tt> method when an import symbol with a leading colonis requested, as in <tt class="literal">use POSIX ":sys_wait_h"</tt>. The keys are thecolon tags, but without the loading colon. The values should bereferences to arrays containing symbols to import when thecolon tag is requested, all of which must also appear in either<tt class="literal">@EXPORT</tt> or <tt class="literal">@EXPORT_OK</tt>. It is not exempt from <tt class="literal">use strict</tt>.See <a href="ch11_01.htm">Chapter 11, "Modules"</a>.</p></dd><dt><b><tt class="literal">$EXTENDED_OS_ERROR</tt></b></dt><dt><b><tt class="literal">$^E</tt></b></dt><dd><p><a name="INDEX-4458"></a><a name="INDEX-4459"></a></p><p>[ALL] Error information specific to the current operating system. UnderUnix, <tt class="literal">$^E</tt> is identical to <tt class="literal">$!</tt> (<tt class="literal">$OS_ERROR</tt>), but it differs under OS/2, VMS,and Microsoft systems, and on MacPerl. See your port's information forspecifics. Caveats mentioned in the description of <tt class="literal">$!</tt> generallyapply to <tt class="literal">$^E</tt> as well. (Mnemonic: extra error explanation.)</p></dd><dt><b><tt class="literal">@F</tt></b></dt><dd><p><a name="INDEX-4460"></a><a name="INDEX-4461"></a><a name="INDEX-4462"></a><a name="INDEX-4463"></a>[PKG] The array into which the input line's fields are split when the<span class="option">-a</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -