perlvar.html
来自「perl教程」· HTML 代码 · 共 1,313 行 · 第 1/5 页
HTML
1,313 行
<dd>
<p>The output record separator for the print operator. If defined, this
value is printed after the last of print's arguments. Default is <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a>.
(Mnemonic: you set <a href="#item___"><code>$\</code></a> instead of adding "\n" at the end of the print.
Also, it's just like <a href="#item___"><code>$/</code></a>, but it's what you get "back" from Perl.)</p>
</dd>
</li>
<dt><strong><a name="item__list_separator">$LIST_SEPARATOR</a></strong>
<dt><strong><a name="item__">$"</a></strong>
<dd>
<p>This is like <a href="#item___"><code>$,</code></a> except that it applies to array and slice values
interpolated into a double-quoted string (or similar interpreted
string). Default is a space. (Mnemonic: obvious, I think.)</p>
</dd>
</li>
<dt><strong><a name="item__subscript_separator">$SUBSCRIPT_SEPARATOR</a></strong>
<dt><strong><a name="item__subsep">$SUBSEP</a></strong>
<dt><strong><a name="item___">$;</a></strong>
<dd>
<p>The subscript separator for multidimensional array emulation. If you
refer to a hash element as</p>
</dd>
<dd>
<pre>
<span class="variable">$foo</span><span class="operator">{</span><span class="variable">$a</span><span class="operator">,</span><span class="variable">$b</span><span class="operator">,</span><span class="variable">$c</span><span class="operator">}</span>
</pre>
</dd>
<dd>
<p>it really means</p>
</dd>
<dd>
<pre>
<span class="variable">$foo</span><span class="operator">{</span><span class="keyword">join</span><span class="operator">(</span><span class="variable">$;</span><span class="operator">,</span> <span class="variable">$a</span><span class="operator">,</span> <span class="variable">$b</span><span class="operator">,</span> <span class="variable">$c</span><span class="operator">)</span><span class="operator">}</span>
</pre>
</dd>
<dd>
<p>But don't put</p>
</dd>
<dd>
<pre>
<span class="variable">@foo</span><span class="operator">{</span><span class="variable">$a</span><span class="operator">,</span><span class="variable">$b</span><span class="operator">,</span><span class="variable">$c</span><span class="operator">}</span> <span class="comment"># a slice--note the @</span>
</pre>
</dd>
<dd>
<p>which means</p>
</dd>
<dd>
<pre>
<span class="operator">(</span><span class="variable">$foo</span><span class="operator">{</span><span class="variable">$a</span><span class="operator">}</span><span class="operator">,</span><span class="variable">$foo</span><span class="operator">{</span><span class="variable">$b</span><span class="operator">}</span><span class="operator">,</span><span class="variable">$foo</span><span class="operator">{</span><span class="variable">$c</span><span class="operator">}</span><span class="operator">)</span>
</pre>
</dd>
<dd>
<p>Default is "\034", the same as SUBSEP in <strong>awk</strong>. If your
keys contain binary data there might not be any safe value for <a href="#item___"><code>$;</code></a>.
(Mnemonic: comma (the syntactic subscript separator) is a
semi-semicolon. Yeah, I know, it's pretty lame, but <a href="#item___"><code>$,</code></a> is already
taken for something more important.)</p>
</dd>
<dd>
<p>Consider using "real" multidimensional arrays as described
in <a href="../../lib/Pod/perllol.html">the perllol manpage</a>.</p>
</dd>
</li>
<dt><strong><a name="item___">$#</a></strong>
<dd>
<p>The output format for printed numbers. This variable is a half-hearted
attempt to emulate <strong>awk</strong>'s OFMT variable. There are times, however,
when <strong>awk</strong> and Perl have differing notions of what counts as
numeric. The initial value is "%.<em>n</em>g", where <em>n</em> is the value
of the macro DBL_DIG from your system's <em>float.h</em>. This is different from
<strong>awk</strong>'s default OFMT setting of "%.6g", so you need to set <a href="#item___"><code>$#</code></a>
explicitly to get <strong>awk</strong>'s value. (Mnemonic: # is the number sign.)</p>
</dd>
<dd>
<p>Use of <a href="#item___"><code>$#</code></a> is deprecated.</p>
</dd>
</li>
<dt><strong><a name="item_format_page_number">HANDLE-><code>format_page_number(EXPR)</code></a></strong>
<dt><strong><a name="item__format_page_number">$FORMAT_PAGE_NUMBER</a></strong>
<dt><strong><a name="item___">$%</a></strong>
<dd>
<p>The current page number of the currently selected output channel.
Used with formats.
(Mnemonic: % is page number in <strong>nroff</strong>.)</p>
</dd>
</li>
<dt><strong><a name="item_format_lines_per_page">HANDLE-><code>format_lines_per_page(EXPR)</code></a></strong>
<dt><strong><a name="item__format_lines_per_page">$FORMAT_LINES_PER_PAGE</a></strong>
<dt><strong><a name="item___">$=</a></strong>
<dd>
<p>The current page length (printable lines) of the currently selected
output channel. Default is 60.
Used with formats.
(Mnemonic: = has horizontal lines.)</p>
</dd>
</li>
<dt><strong><a name="item_format_lines_left">HANDLE-><code>format_lines_left(EXPR)</code></a></strong>
<dt><strong><a name="item__format_lines_left">$FORMAT_LINES_LEFT</a></strong>
<dt><strong><a name="item__">$-</a></strong>
<dd>
<p>The number of lines left on the page of the currently selected output
channel.
Used with formats.
(Mnemonic: lines_on_page - lines_printed.)</p>
</dd>
</li>
<dt><strong><a name="item__last_match_start">@LAST_MATCH_START</a></strong>
<dt><strong><a name="item__">@-</a></strong>
<dd>
<p>$-[0] is the offset of the start of the last successful match.
<code>$-[</code><em>n</em><code>]</code> is the offset of the start of the substring matched by
<em>n</em>-th subpattern, or undef if the subpattern did not match.</p>
</dd>
<dd>
<p>Thus after a match against $_, $& coincides with <code>substr $_, $-[0],
$+[0] - $-[0]</code>. Similarly, $<em>n</em> coincides with <code>substr $_, $-[n],
$+[n] - $-[n]</code> if <code>$-[n]</code> is defined, and $+ coincides with
<code>substr $_, $-[$#-], $+[$#-] - $-[$#-]</code>. One can use <code>$#-</code> to find the last
matched subgroup in the last successful match. Contrast with
<code>$#+</code>, the number of subgroups in the regular expression. Compare
with <a href="#item___"><code>@+</code></a>.</p>
</dd>
<dd>
<p>This array holds the offsets of the beginnings of the last
successful submatches in the currently active dynamic scope.
<code>$-[0]</code> is the offset into the string of the beginning of the
entire match. The <em>n</em>th element of this array holds the offset
of the <em>n</em>th submatch, so <code>$-[1]</code> is the offset where $1
begins, <code>$-[2]</code> the offset where $2 begins, and so on.</p>
</dd>
<dd>
<p>After a match against some variable $var:</p>
</dd>
<dl>
<dt><strong><a name="item_substr"><a href="#item___"><code>$`</code></a> is the same as <code>substr($var, 0, $-[0])</code></a></strong>
<dt><strong><a href="#item___"><code>$&</code></a> is the same as <code>substr($var, $-[0], $+[0] - $-[0])</code></strong>
<dt><strong><a href="#item___"><code>$'</code></a> is the same as <code>substr($var, $+[0])</code></strong>
<dt><strong><code>$1</code> is the same as <code>substr($var, $-[1], $+[1] - $-[1])</code></strong>
<dt><strong><code>$2</code> is the same as <code>substr($var, $-[2], $+[2] - $-[2])</code></strong>
<dt><strong><code>$3</code> is the same as <code>substr($var, $-[3], $+[3] - $-[3])</code></strong>
</dl>
<dt><strong><a name="item_format_name">HANDLE-><code>format_name(EXPR)</code></a></strong>
<dt><strong><a name="item__format_name">$FORMAT_NAME</a></strong>
<dt><strong><a name="item___">$~</a></strong>
<dd>
<p>The name of the current report format for the currently selected output
channel. Default is the name of the filehandle. (Mnemonic: brother to
<a href="#item___"><code>$^</code></a>.)</p>
</dd>
</li>
<dt><strong><a name="item_format_top_name">HANDLE-><code>format_top_name(EXPR)</code></a></strong>
<dt><strong><a name="item__format_top_name">$FORMAT_TOP_NAME</a></strong>
<dt><strong><a name="item___">$^</a></strong>
<dd>
<p>The name of the current top-of-page format for the currently selected
output channel. Default is the name of the filehandle with _TOP
appended. (Mnemonic: points to top of page.)</p>
</dd>
</li>
<dt><strong><a name="item_format_line_break_characters">IO::Handle->format_line_break_characters EXPR</a></strong>
<dt><strong><a name="item__format_line_break_characters">$FORMAT_LINE_BREAK_CHARACTERS</a></strong>
<dt><strong><a name="item___">$:</a></strong>
<dd>
<p>The current set of characters after which a string may be broken to
fill continuation fields (starting with ^) in a format. Default is
" \n-", to break on whitespace or hyphens. (Mnemonic: a "colon" in
poetry is a part of a line.)</p>
</dd>
</li>
<dt><strong><a name="item_format_formfeed">IO::Handle->format_formfeed EXPR</a></strong>
<dt><strong><a name="item__format_formfeed">$FORMAT_FORMFEED</a></strong>
<dt><strong><a name="item___l">$^L</a></strong>
<dd>
<p>What formats output as a form feed. Default is \f.</p>
</dd>
</li>
<dt><strong><a name="item__accumulator">$ACCUMULATOR</a></strong>
<dt><strong><a name="item___a">$^A</a></strong>
<dd>
<p>The current value of the <a href="../../lib/Pod/perlfunc.html#item_write"><code>write()</code></a> accumulator for <a href="../../lib/Pod/perlfunc.html#item_format"><code>format()</code></a> lines. A format
contains <a href="../../lib/Pod/perlfunc.html#item_formline"><code>formline()</code></a> calls that put their result into <a href="#item___a"><code>$^A</code></a>. After
calling its format, <a href="../../lib/Pod/perlfunc.html#item_write"><code>write()</code></a> prints out the contents of <a href="#item___a"><code>$^A</code></a> and empties.
So you never really see the contents of <a href="#item___a"><code>$^A</code></a> unless you call
<a href="../../lib/Pod/perlfunc.html#item_formline"><code>formline()</code></a> yourself and then look at it. See <a href="../../lib/Pod/perlform.html">the perlform manpage</a> and
<a href="../../lib/Pod/perlfunc.html#formline__">formline() in the perlfunc manpage</a>.</p>
</dd>
</li>
<dt><strong><a name="item__child_error">$CHILD_ERROR</a></strong>
<dt><strong><a name="item__">$?</a></strong>
<dd>
<p>The status returned by the last pipe close, backtick (<code>``</code>) command,
successful call to <a href="../../lib/Pod/perlfunc.html#item_wait"><code>wait()</code></a> or waitpid(), or from the <a href="../../lib/Pod/perlfunc.html#item_system"><code>system()</code></a>
operator. This is just the 16-bit status word returned by the
<a href="../../lib/Pod/perlfunc.html#item_wait"><code>wait()</code></a> system call (or else is made up to look like it). Thus, the
exit value of the subprocess is really (<a href="#item__"><code>$? >> 8</code></a>), and
<a href="#item__"><code>$? & 127</code></a> gives which signal, if any, the process died from, and
<a href="#item__"><code>$? & 128</code></a> reports whether there was a core dump. (Mnemonic:
similar to <strong>sh</strong> and <strong>ksh</strong>.)</p>
</dd>
<dd>
<p>Additionally, if the <code>h_errno</code> variable is supported in C, its value
is returned via $? if any <code>gethost*()</code> function fails.</p>
</dd>
<dd>
<p>If you have installed a signal handler for <code>SIGCHLD</code>, the
value of <a href="#item__"><code>$?</code></a> will usually be wrong outside that handler.</p>
</dd>
<dd>
<p>Inside an <code>END</code> subroutine <a href="#item__"><code>$?</code></a> contains the value that is going to be
given to <a href="../../lib/Pod/perlfunc.html#item_exit"><code>exit()</code></a>. You can modify <a href="#item__"><code>$?</code></a> in an <code>END</code> subroutine to
change the exit status of your program. For example:</p>
</dd>
<dd>
<pre>
<span class="keyword">END</span> <span class="operator">{</span>
<span class="variable">$?</span> <span class="operator">=</span> <span class="number">1</span> <span class="keyword">if</span> <span class="variable">$?</span> <span class="operator">==</span> <span class="number">255</span><span class="operator">;</span> <span class="comment"># die would make it 255</span>
<span class="operator">}</span>
</pre>
</dd>
<dd>
<p>Under VMS, the pragma <code>use vmsish 'status'</code> makes <a href="#item__"><code>$?</code></a> reflect the
actual VMS exit status, instead of the default emulation of POSIX
status; see <a href="../../lib/Pod/perlvms.html#_">$? in the perlvms manpage</a> for details.</p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?