perl5004delta.html

来自「perl教程」· HTML 代码 · 共 1,154 行 · 第 1/5 页

HTML
1,154 行
字号
<p>The <a href="../../lib/Pod/perlvar.html#item___"><code>$)</code></a> special variable has always (well, in Perl 5, at least)
reflected not only the current effective group, but also the group list
as returned by the <code>getgroups()</code> C function (if there is one).
However, until this release, there has not been a way to call the
<code>setgroups()</code> C function from Perl.</p>
<p>In Perl 5.004, assigning to <a href="../../lib/Pod/perlvar.html#item___"><code>$)</code></a> is exactly symmetrical with examining
it: The first number in its string value is used as the effective gid;
if there are any numbers after the first one, they are passed to the
<code>setgroups()</code> C function (if there is one).</p>
<p>
</p>
<h2><a name="fixed_parsing_of____digit______digit___etc_">Fixed parsing of $$&lt;digit&gt;, &amp;$&lt;digit&gt;, etc.</a></h2>
<p>Perl versions before 5.004 misinterpreted any type marker followed by
&quot;$&quot; and a digit.  For example, &quot;$$0&quot; was incorrectly taken to mean
&quot;${$}0&quot; instead of &quot;${$0}&quot;.  This bug is (mostly) fixed in Perl 5.004.</p>
<p>However, the developers of Perl 5.004 could not fix this bug completely,
because at least two widely-used modules depend on the old meaning of
&quot;$$0&quot; in a string.  So Perl 5.004 still interprets &quot;$$&lt;digit&gt;&quot; in the
old (broken) way inside strings; but it generates this message as a
warning.  And in Perl 5.005, this special treatment will cease.</p>
<p>
</p>
<h2><a name="fixed_localization_of___digit_______etc_">Fixed localization of $&lt;digit&gt;, $&amp;, etc.</a></h2>
<p>Perl versions before 5.004 did not always properly localize the
regex-related special variables.  Perl 5.004 does localize them, as
the documentation has always said it should.  This may result in $1,
$2, etc. no longer being set where existing programs use them.</p>
<p>
</p>
<h2><a name="no_resetting_of____on_implicit_close">No resetting of $. on implicit close</a></h2>
<p>The documentation for Perl 5.0 has always stated that <a href="../../lib/Pod/perlvar.html#item___"><code>$.</code></a> is <em>not</em>
reset when an already-open file handle is reopened with no intervening
call to <a href="../../lib/Pod/perlfunc.html#item_close"><code>close</code></a>.  Due to a bug, perl versions 5.000 through 5.003
<em>did</em> reset <a href="../../lib/Pod/perlvar.html#item___"><code>$.</code></a> under that circumstance; Perl 5.004 does not.</p>
<p>
</p>
<h2><a name="wantarray_may_return_undef"><a href="../../lib/Pod/perlfunc.html#item_wantarray"><code>wantarray</code></a> may return undef</a></h2>
<p>The <a href="../../lib/Pod/perlfunc.html#item_wantarray"><code>wantarray</code></a> operator returns true if a subroutine is expected to
return a list, and false otherwise.  In Perl 5.004, <a href="../../lib/Pod/perlfunc.html#item_wantarray"><code>wantarray</code></a> can
also return the undefined value if a subroutine's return value will
not be used at all, which allows subroutines to avoid a time-consuming
calculation of a return value if it isn't going to be used.</p>
<p>
</p>
<h2><a name="eval_expr_determines_value_of_expr_in_scalar_context"><a href="../../lib/Pod/perlfunc.html#item_eval"><code>eval EXPR</code></a> determines value of EXPR in scalar context</a></h2>
<p>Perl (version 5) used to determine the value of EXPR inconsistently,
sometimes incorrectly using the surrounding context for the determination.
Now, the value of EXPR (before being parsed by eval) is always determined in
a scalar context.  Once parsed, it is executed as before, by providing
the context that the scope surrounding the eval provided.  This change
makes the behavior Perl4 compatible, besides fixing bugs resulting from
the inconsistent behavior.  This program:</p>
<pre>
    <span class="variable">@a</span> <span class="operator">=</span> <span class="string">qw(time now is time)</span><span class="operator">;</span>
    <span class="keyword">print</span> <span class="keyword">eval</span> <span class="variable">@a</span><span class="operator">;</span>
    <span class="keyword">print</span> <span class="string">'|'</span><span class="operator">,</span> <span class="keyword">scalar</span> <span class="keyword">eval</span> <span class="variable">@a</span><span class="operator">;</span>
</pre>
<p>used to print something like &quot;timenowis881399109|4&quot;, but now (and in perl4)
prints &quot;4|4&quot;.</p>
<p>
</p>
<h2><a name="changes_to_tainting_checks">Changes to tainting checks</a></h2>
<p>A bug in previous versions may have failed to detect some insecure
conditions when taint checks are turned on.  (Taint checks are used
in setuid or setgid scripts, or when explicitly turned on with the
<a href="../../lib/Pod/perlrun.html#item__2dt"><code>-T</code></a> invocation option.)  Although it's unlikely, this may cause a
previously-working script to now fail -- which should be construed
as a blessing, since that indicates a potentially-serious security
hole was just plugged.</p>
<p>The new restrictions when tainting include:</p>
<dl>
<dt><strong><a name="item_glob">No <code>glob()</code> or &lt;*&gt;</a></strong>

<dd>
<p>These operators may spawn the C shell (csh), which cannot be made
safe.  This restriction will be lifted in a future version of Perl
when globbing is implemented without the use of an external program.</p>
</dd>
</li>
<dt><strong><a name="item_no_spawning_if_tainted__24cdpath_2c__24env_2c__24b">No spawning if tainted $CDPATH, $ENV, $BASH_ENV</a></strong>

<dd>
<p>These environment variables may alter the behavior of spawned programs
(especially shells) in ways that subvert security.  So now they are
treated as dangerous, in the manner of $IFS and $PATH.</p>
</dd>
</li>
<dt><strong><a name="item_no_spawning_if_tainted__24term_doesn_27t_look_like">No spawning if tainted $TERM doesn't look like a terminal name</a></strong>

<dd>
<p>Some termcap libraries do unsafe things with $TERM.  However, it would be
unnecessarily harsh to treat all $TERM values as unsafe, since only shell
metacharacters can cause trouble in $TERM.  So a tainted $TERM is
considered to be safe if it contains only alphanumerics, underscores,
dashes, and colons, and unsafe if it contains other characters (including
whitespace).</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="new_opcode_module_and_revised_safe_module">New Opcode module and revised Safe module</a></h2>
<p>A new Opcode module supports the creation, manipulation and
application of opcode masks.  The revised Safe module has a new API
and is implemented using the new Opcode module.  Please read the new
Opcode and Safe documentation.</p>
<p>
</p>
<h2><a name="embedding_improvements">Embedding improvements</a></h2>
<p>In older versions of Perl it was not possible to create more than one
Perl interpreter instance inside a single process without leaking like a
sieve and/or crashing.  The bugs that caused this behavior have all been
fixed.  However, you still must take care when embedding Perl in a C
program.  See the updated perlembed manpage for tips on how to manage
your interpreters.</p>
<p>
</p>
<h2><a name="internal_change__filehandle_class_based_on_io____classes">Internal change: FileHandle class based on IO::* classes</a></h2>
<p>File handles are now stored internally as type IO::Handle.  The
FileHandle module is still supported for backwards compatibility, but
it is now merely a front end to the IO::* modules -- specifically,
IO::Handle, IO::Seekable, and IO::File.  We suggest, but do not
require, that you use the IO::* modules in new code.</p>
<p>In harmony with this change, <code>*GLOB{FILEHANDLE}</code> is now just a
backward-compatible synonym for <code>*GLOB{IO}</code>.</p>
<p>
</p>
<h2><a name="internal_change__perlio_abstraction_interface">Internal change: PerlIO abstraction interface</a></h2>
<p>It is now possible to build Perl with AT&amp;T's sfio IO package
instead of stdio.  See <a href="../../lib/Pod/perlapio.html">the perlapio manpage</a> for more details, and
the <em>INSTALL</em> file for how to use it.</p>
<p>
</p>
<h2><a name="new_and_changed_syntax">New and changed syntax</a></h2>
<dl>
<dt><strong><a name="item__coderef__params_">$coderef-&gt;(PARAMS)</a></strong>

<dd>
<p>A subroutine reference may now be suffixed with an arrow and a
(possibly empty) parameter list.  This syntax denotes a call of the
referenced subroutine, with the given parameters (if any).</p>
</dd>
<dd>
<p>This new syntax follows the pattern of <code>$hashref-&gt;{FOO}</code> and
<code>$aryref-&gt;[$foo]</code>: You may now write <code>&amp;$subref($foo)</code> as
<code>$subref-&gt;($foo)</code>.  All these arrow terms may be chained;
thus, <code>&amp;{$table-&gt;{FOO}}($bar)</code> may now be written
<code>$table-&gt;{FOO}-&gt;($bar)</code>.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="new_and_changed_builtin_constants">New and changed builtin constants</a></h2>
<dl>
<dt><strong><a name="item___package__">__PACKAGE__</a></strong>

<dd>
<p>The current package name at compile time, or the undefined value if
there is no current package (due to a <code>package;</code> directive).  Like
<code>__FILE__</code> and <code>__LINE__</code>, <a href="#item___package__"><code>__PACKAGE__</code></a> does <em>not</em> interpolate
into strings.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="new_and_changed_builtin_variables">New and changed builtin variables</a></h2>
<dl>
<dt><strong><a name="item___e">$^E</a></strong>

<dd>
<p>Extended error message on some platforms.  (Also known as
$EXTENDED_OS_ERROR if you <code>use English</code>).</p>
</dd>
</li>
<dt><strong><a name="item___h">$^H</a></strong>

<dd>
<p>The current set of syntax checks enabled by <code>use strict</code>.  See the
documentation of <code>strict</code> for more details.  Not actually new, but
newly documented.
Because it is intended for internal use by Perl core components,
there is no <code>use English</code> long name for this variable.</p>
</dd>
</li>
<dt><strong><a name="item___m">$^M</a></strong>

<dd>
<p>By default, running out of memory it is not trappable.  However, if
compiled for this, Perl may use the contents of <a href="#item___m"><code>$^M</code></a> as an emergency
pool after die()ing with this message.  Suppose that your Perl were
compiled with -DPERL_EMERGENCY_SBRK 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">&lt;&lt;</span><span class="number">16</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<p>would allocate a 64K buffer for use when in emergency.
See the <em>INSTALL</em> file for information on how to enable this option.
As a disincentive to casual use of this advanced feature,
there is no <code>use English</code> long name for this variable.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="new_and_changed_builtin_functions">New and changed builtin functions</a></h2>
<dl>
<dt><strong><a name="item_delete_on_slices">delete on slices</a></strong>

<dd>
<p>This now works.  (e.g. <code>delete @ENV{'PATH', 'MANPATH'}</code>)</p>
</dd>
</li>
<dt><strong><a name="item_flock">flock</a></strong>

<dd>
<p>is now supported on more platforms, prefers fcntl to lockf when
emulating, and always flushes before (un)locking.</p>
</dd>
</li>
<dt><strong><a name="item_printf_and_sprintf">printf and sprintf</a></strong>

<dd>
<p>Perl now implements these functions itself; it doesn't use the C
library function <a href="../../lib/Pod/perlfunc.html#item_sprintf"><code>sprintf()</code></a> any more, except for floating-point
numbers, and even then only known flags are allowed.  As a result, it
is now possible to know which conversions and flags will work, and

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?