perlvar.html
来自「perl教程」· HTML 代码 · 共 1,313 行 · 第 1/5 页
HTML
1,313 行
running. (Mnemonic: same as <strong>sh</strong> and <strong>ksh</strong>.)</p>
</dd>
<dd>
<p>Note that there are platform specific limitations on the maximum
length of <a href="#item__0"><code>$0</code></a>. In the most extreme case it may be limited to the
space occupied by the original <a href="#item__0"><code>$0</code></a>.</p>
</dd>
<dd>
<p>In some platforms there may be arbitrary amount of padding, for
example space characters, after the modified name as shown by <code>ps</code>.
In some platforms this padding may extend all the way to the original
length of the argument area, no matter what you do (this is the case
for example with Linux 2.2).</p>
</dd>
<dd>
<p>Note for BSD users: setting <a href="#item__0"><code>$0</code></a> does not completely remove "perl"
from the <code>ps(1)</code> output. For example, setting <a href="#item__0"><code>$0</code></a> to <code>"foobar"</code> may
result in <code>"perl: foobar (perl)"</code> (whether both the <code>"perl: "</code> prefix
and the " (perl)" suffix are shown depends on your exact BSD variant
and version). This is an operating system feature, Perl cannot help it.</p>
</dd>
<dd>
<p>In multithreaded scripts Perl coordinates the threads so that any
thread may modify its copy of the <a href="#item__0"><code>$0</code></a> and the change becomes visible
to <code>ps(1)</code> (assuming the operating system plays along). Note that
the view of <a href="#item__0"><code>$0</code></a> the other threads have will not change since they
have their own copies of it.</p>
</dd>
</li>
<dt><strong><a name="item___">$[</a></strong>
<dd>
<p>The index of the first element in an array, and of the first character
in a substring. Default is 0, but you could theoretically set it
to 1 to make Perl behave more like <strong>awk</strong> (or Fortran) when
subscripting and when evaluating the <a href="../../lib/Pod/perlfunc.html#item_index"><code>index()</code></a> and <a href="#item_substr"><code>substr()</code></a> functions.
(Mnemonic: [ begins subscripts.)</p>
</dd>
<dd>
<p>As of release 5 of Perl, assignment to <a href="#item___"><code>$[</code></a> is treated as a compiler
directive, and cannot influence the behavior of any other file.
(That's why you can only assign compile-time constants to it.)
Its use is highly discouraged.</p>
</dd>
<dd>
<p>Note that, unlike other compile-time directives (such as <a href="../../lib/strict.html">the strict manpage</a>),
assignment to <a href="#item___"><code>$[</code></a> can be seen from outer lexical scopes in the same file.
However, you can use <a href="../../lib/Pod/perlfunc.html#item_local"><code>local()</code></a> on it to strictly bind its value to a
lexical block.</p>
</dd>
</li>
<dt><strong><a name="item___">$]</a></strong>
<dd>
<p>The version + patchlevel / 1000 of the Perl interpreter. This variable
can be used to determine whether the Perl interpreter executing a
script is in the right range of versions. (Mnemonic: Is this version
of perl in the right bracket?) Example:</p>
</dd>
<dd>
<pre>
<span class="keyword">warn</span> <span class="string">"No checksumming!\n"</span> <span class="keyword">if</span> <span class="variable">$]</span> <span class="operator"><</span> <span class="number">3.019</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>See also the documentation of <a href="../../lib/Pod/perlfunc.html#item_use"><code>use VERSION</code></a> and <a href="../../lib/Pod/perlfunc.html#item_require"><code>require VERSION</code></a>
for a convenient way to fail if the running Perl interpreter is too old.</p>
</dd>
<dd>
<p>When testing the variable, to steer clear of floating point
inaccuracies you might want to prefer the inequality tests <code><</code>
and <code>></code> to the tests containing equivalence: <code><=</code>, <code>==</code>,
and <code>>=</code>.</p>
</dd>
<dd>
<p>The floating point representation can sometimes lead to inaccurate
numeric comparisons. See <a href="#item___v"><code>$^V</code></a> for a more modern representation of
the Perl version that allows accurate string comparisons.</p>
</dd>
</li>
<dt><strong><a name="item__compiling">$COMPILING</a></strong>
<dt><strong><a name="item___c">$^C</a></strong>
<dd>
<p>The current value of the flag associated with the <strong>-c</strong> switch.
Mainly of use with <strong>-MO=...</strong> to allow code to alter its behavior
when being compiled, such as for example to AUTOLOAD at compile
time rather than normal, deferred loading. See <em>perlcc</em>. Setting
<a href="#item___c"><code>$^C = 1</code></a> is similar to calling <code>B::minus_c</code>.</p>
</dd>
</li>
<dt><strong><a name="item__debugging">$DEBUGGING</a></strong>
<dt><strong><a name="item___d">$^D</a></strong>
<dd>
<p>The current value of the debugging flags. (Mnemonic: value of <strong>-D</strong>
switch.) May be read or set. Like its command-line equivalent, you can use
numeric or symbolic values, eg <a href="#item___d"><code>$^D = 10</code></a> or <a href="#item___d"><code>$^D = "st"</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item__system_fd_max">$SYSTEM_FD_MAX</a></strong>
<dt><strong><a name="item___f">$^F</a></strong>
<dd>
<p>The maximum system file descriptor, ordinarily 2. System file
descriptors are passed to exec()ed processes, while higher file
descriptors are not. Also, during an open(), system file descriptors are
preserved even if the <a href="../../lib/Pod/perlfunc.html#item_open"><code>open()</code></a> fails. (Ordinary file descriptors are
closed before the <a href="../../lib/Pod/perlfunc.html#item_open"><code>open()</code></a> is attempted.) The close-on-exec
status of a file descriptor will be decided according to the value of
<a href="#item___f"><code>$^F</code></a> when the corresponding file, pipe, or socket was opened, not the
time of the exec().</p>
</dd>
</li>
<dt><strong><a name="item___h">$^H</a></strong>
<dd>
<p>WARNING: This variable is strictly for internal use only. Its availability,
behavior, and contents are subject to change without notice.</p>
</dd>
<dd>
<p>This variable contains compile-time hints for the Perl interpreter. At the
end of compilation of a BLOCK the value of this variable is restored to the
value when the interpreter started to compile the BLOCK.</p>
</dd>
<dd>
<p>When perl begins to parse any block construct that provides a lexical scope
(e.g., eval body, required file, subroutine body, loop body, or conditional
block), the existing value of $^H is saved, but its value is left unchanged.
When the compilation of the block is completed, it regains the saved value.
Between the points where its value is saved and restored, code that
executes within BEGIN blocks is free to change the value of $^H.</p>
</dd>
<dd>
<p>This behavior provides the semantic of lexical scoping, and is used in,
for instance, the <code>use strict</code> pragma.</p>
</dd>
<dd>
<p>The contents should be an integer; different bits of it are used for
different pragmatic flags. Here's an example:</p>
</dd>
<dd>
<pre>
<span class="keyword">sub</span><span class="variable"> add_100 </span><span class="operator">{</span> <span class="variable">$^H</span> <span class="operator">|=</span> <span class="number">0x100</span> <span class="operator">}</span>
</pre>
</dd>
<dd>
<pre>
<span class="keyword">sub</span><span class="variable"> foo </span><span class="operator">{</span>
<span class="keyword">BEGIN</span> <span class="operator">{</span> <span class="variable">add_100</span><span class="operator">()</span> <span class="operator">}</span>
<span class="variable">bar</span><span class="operator">-></span><span class="variable">baz</span><span class="operator">(</span><span class="variable">$boon</span><span class="operator">);</span>
<span class="operator">}</span>
</pre>
</dd>
<dd>
<p>Consider what happens during execution of the BEGIN block. At this point
the BEGIN block has already been compiled, but the body of <code>foo()</code> is still
being compiled. The new value of $^H will therefore be visible only while
the body of <code>foo()</code> is being compiled.</p>
</dd>
<dd>
<p>Substitution of the above BEGIN block with:</p>
</dd>
<dd>
<pre>
<span class="keyword">BEGIN</span> <span class="operator">{</span> <span class="keyword">require</span> <span class="variable">strict</span><span class="operator">;</span> <span class="variable">strict</span><span class="operator">-></span><span class="variable">import</span><span class="operator">(</span><span class="string">'vars'</span><span class="operator">)</span> <span class="operator">}</span>
</pre>
</dd>
<dd>
<p>demonstrates how <code>use strict 'vars'</code> is implemented. Here's a conditional
version of the same lexical pragma:</p>
</dd>
<dd>
<pre>
<span class="keyword">BEGIN</span> <span class="operator">{</span> <span class="keyword">require</span> <span class="variable">strict</span><span class="operator">;</span> <span class="variable">strict</span><span class="operator">-></span><span class="variable">import</span><span class="operator">(</span><span class="string">'vars'</span><span class="operator">)</span> <span class="keyword">if</span> <span class="variable">$condition</span> <span class="operator">}</span>
</pre>
</dd>
</li>
<dt><strong><a name="item___h">%^H</a></strong>
<dd>
<p>WARNING: This variable is strictly for internal use only. Its availability,
behavior, and contents are subject to change without notice.</p>
</dd>
<dd>
<p>The %^H hash provides the same scoping semantic as $^H. This makes it
useful for implementation of lexically scoped pragmas.</p>
</dd>
</li>
<dt><strong><a name="item__inplace_edit">$INPLACE_EDIT</a></strong>
<dt><strong><a name="item___i">$^I</a></strong>
<dd>
<p>The current value of the inplace-edit extension. Use <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> to disable
inplace editing. (Mnemonic: value of <strong>-i</strong> switch.)</p>
</dd>
</li>
<dt><strong><a name="item___m">$^M</a></strong>
<dd>
<p>By default, running out of memory is an untrappable, fatal error.
However, if suitably built, Perl can use the contents of <a href="#item___m"><code>$^M</code></a>
as an emergency memory pool after die()ing. Suppose that your Perl
were compiled with <code>-DPERL_EMERGENCY_SBRK</code> and used Perl's malloc.
Then</p>
</dd>
<dd>
<pre>
<span class="variable">$^M</span> <span class="operator">=</span> <span class="string">'a'</span> <span class="operator">x</span> <span class="operator">(</span><span class="number">1</span> <span class="operator"><<</span> <span class="number">16</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>would allocate a 64K buffer for use in an emergency. See the
<em>INSTALL</em> file in the Perl distribution for information on how to
add custom C compilation flags when compiling perl. To discourage casual
use of this advanced feature, there is no <a href="../../lib/English.html">English</a> long name for
this variable.</p>
</dd>
</li>
<dt><strong><a name="item__osname">$OSNAME</a></strong>
<dt><strong><a name="item___o">$^O</a></strong>
<dd>
<p>The name of the operating system under which this copy of Perl was
built, as determined during the configuration process. The value
is identical to <code>$Config{'osname'}</code>. See also <a href="../../lib/Config.html">the Config manpage</a> and the
<strong>-V</strong> command-line switch documented in <a href="../../lib/Pod/perlrun.html">the perlrun manpage</a>.</p>
</dd>
<dd>
<p>In Windows platforms, $^O is not very helpful: since it is always
<code>MSWin32</code>, it doesn't tell the difference between
95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or
Win32::GetOSVersion() (see <a href="../../lib/Win32.html">the Win32 manpage</a> and <a href="../../lib/Pod/perlport.html">the perlport manpage</a>) to distinguish
between the variants.</p>
</dd>
</li>
<dt><strong><a name="item____open_">${^OPEN}</a></strong>
<dd>
<p>An internal variable used by PerlIO. A string in two parts, separated
by a <code>\0</code> byte, the first part describes the input layers, the second
part describes the output layers.</p>
</dd>
</li>
<dt><strong><a name="item__perldb">$PERLDB</a></strong>
<dt><strong><a name="item___p">$^P</a></strong>
<dd>
<p>The internal variable for debugging support. The meanings of the
various bits are subject to change, but currently indicate:</p>
</dd>
<ol>
<li><strong><a name="item_x01">x01</a></strong>
<p>Debug subroutine
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?