perl58delta.html
来自「perl教程」· HTML 代码 · 共 1,127 行 · 第 1/5 页
HTML
1,127 行
algorithm "One-at-a-Time" produces a different hashed key order.
More details are in <a href="#performance_enhancements">Performance Enhancements</a>.</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_lstat"><code>lstat(FILEHANDLE)</code></a> now gives a warning because the operation makes no sense.
In future releases this may become a fatal error.</p>
</li>
<li>
<p>Spurious syntax errors generated in certain situations, when <a href="../../lib/Pod/perlfunc.html#item_glob"><code>glob()</code></a>
caused File::Glob to be loaded for the first time, have been fixed. [561]</p>
</li>
<li>
<p>Lvalue subroutines can now return <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> in list context. However,
the lvalue subroutine feature still remains experimental. [561+]</p>
</li>
<li>
<p>A lost warning "Can't declare ... dereference in my" has been
restored (Perl had it earlier but it became lost in later releases.)</p>
</li>
<li>
<p>A new special regular expression variable has been introduced:
<a href="../../lib/Pod/perlvar.html#item___n"><code>$^N</code></a>, which contains the most-recently closed group (submatch).</p>
</li>
<li>
<p><code>no Module;</code> does not produce an error even if Module does not have an
<code>unimport()</code> method. This parallels the behavior of <a href="../../lib/Pod/perlfunc.html#item_use"><code>use</code></a> vis-a-vis
<a href="../../lib/Pod/perlfunc.html#item_import"><code>import</code></a>. [561]</p>
</li>
<li>
<p>The numerical comparison operators return <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> if either operand
is a NaN. Previously the behaviour was unspecified.</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_our"><code>our</code></a> can now have an experimental optional attribute <code>unique</code> that
affects how global variables are shared among multiple interpreters,
see <a href="../../lib/Pod/perlfunc.html#our">our in the perlfunc manpage</a>.</p>
</li>
<li>
<p>The following builtin functions are now overridable: each(), keys(),
pop(), push(), shift(), splice(), unshift(). [561]</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack() / unpack()</code></a> can now group template letters with <code>()</code> and then
apply repetition/count modifiers on the groups.</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack() / unpack()</code></a> can now process the Perl internal numeric types:
IVs, UVs, NVs-- and also long doubles, if supported by the platform.
The template letters are <code>j</code>, <code>J</code>, <code>F</code>, and <code>D</code>.</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack('U0a*', ...)</code></a> can now be used to force a string to UTF-8.</p>
</li>
<li>
<p>my __PACKAGE__ $obj now works. [561]</p>
</li>
<li>
<p>POSIX::sleep() now returns the number of <em>unslept</em> seconds
(as the POSIX standard says), as opposed to CORE::sleep() which
returns the number of slept seconds.</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_printf"><code>printf()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_sprintf"><code>sprintf()</code></a> now support parameter reordering using the
<code>%\d+\$</code> and <code>*\d+\$</code> syntaxes. For example</p>
<pre>
<span class="keyword">printf</span> <span class="string">"%2\$s %1\$s\n"</span><span class="operator">,</span> <span class="string">"foo"</span><span class="operator">,</span> <span class="string">"bar"</span><span class="operator">;</span>
</pre>
<p>will print "bar foo\n". This feature helps in writing
internationalised software, and in general when the order
of the parameters can vary.</p>
</li>
<li>
<p>The (\&) prototype now works properly. [561]</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_prototype"><code>prototype(\[$@%&])</code></a> is now available to implicitly create references
(useful for example if you want to emulate the <a href="../../lib/Pod/perlfunc.html#item_tie"><code>tie()</code></a> interface).</p>
</li>
<li>
<p>A new command-line option, <a href="../../lib/Pod/perlrun.html#item__2dt"><code>-t</code></a> is available. It is the
little brother of <a href="../../lib/Pod/perlrun.html#item__2dt"><code>-T</code></a>: instead of dying on taint violations,
lexical warnings are given. <strong>This is only meant as a temporary
debugging aid while securing the code of old legacy applications.
This is not a substitute for -T.</strong></p>
</li>
<li>
<p>In other taint news, the <a href="../../lib/Pod/perlfunc.html#item_exec"><code>exec LIST</code></a> and <a href="../../lib/Pod/perlfunc.html#item_system"><code>system LIST</code></a> have now been
considered too risky (think <code>exec @ARGV</code>: it can start any program
with any arguments), and now the said forms cause a warning under
lexical warnings. You should carefully launder the arguments to
guarantee their validity. In future releases of Perl the forms will
become fatal errors so consider starting laundering now.</p>
</li>
<li>
<p>Tied hash interfaces are now required to have the EXISTS and DELETE
methods (either own or inherited).</p>
</li>
<li>
<p>If tr/// is just counting characters, it doesn't attempt to
modify its target.</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_untie"><code>untie()</code></a> will now call an <code>UNTIE()</code> hook if it exists. See <a href="../../lib/Pod/perltie.html">the perltie manpage</a>
for details. [561]</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_utime">utime</a> now supports <code>utime undef, undef, @files</code> to change the
file timestamps to the current time.</p>
</li>
<li>
<p>The rules for allowing underscores (underbars) in numeric constants
have been relaxed and simplified: now you can have an underscore
simply <strong>between digits</strong>.</p>
</li>
<li>
<p>Rather than relying on C's argv[0] (which may not contain a full pathname)
where possible $^X is now set by asking the operating system.
(eg by reading <em>/proc/self/exe</em> on Linux, <em>/proc/curproc/file</em> on FreeBSD)</p>
</li>
<li>
<p>A new variable, <a href="../../lib/Pod/perlvar.html#item____taint_"><code>${^TAINT}</code></a>, indicates whether taint mode is enabled.</p>
</li>
<li>
<p>You can now override the <a href="../../lib/Pod/perlfunc.html#item_readline"><code>readline()</code></a> builtin, and this overrides also
the <FILEHANDLE> angle bracket operator.</p>
</li>
<li>
<p>The command-line options -s and -F are now recognized on the shebang
(#!) line.</p>
</li>
<li>
<p>Use of the <code>/c</code> match modifier without an accompanying <code>/g</code> modifier
elicits a new warning: <code>Use of /c modifier is meaningless without /g</code>.</p>
<p>Use of <code>/c</code> in substitutions, even with <code>/g</code>, elicits
<code>Use of /c modifier is meaningless in s///</code>.</p>
<p>Use of <code>/g</code> with <a href="../../lib/Pod/perlfunc.html#item_split"><code>split</code></a> elicits <code>Use of /g modifier is meaningless
in split</code>.</p>
</li>
<li>
<p>Support for the <code>CLONE</code> special subroutine had been added.
With ithreads, when a new thread is created, all Perl data is cloned,
however non-Perl data cannot be cloned automatically. In <code>CLONE</code> you
can do whatever you need to do, like for example handle the cloning of
non-Perl data, if necessary. <code>CLONE</code> will be executed once for every
package that has it defined or inherited. It will be called in the
context of the new thread, so all modifications are made in the new area.</p>
<p>See <a href="../../lib/Pod/perlmod.html">the perlmod manpage</a></p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="modules_and_pragmata">Modules and Pragmata</a></h1>
<p>
</p>
<h2><a name="new_modules_and_pragmata">New Modules and Pragmata</a></h2>
<ul>
<li>
<p><code>Attribute::Handlers</code>, originally by Damian Conway and now maintained
by Arthur Bergman, allows a class to define attribute handlers.</p>
<pre>
<span class="keyword">package</span> <span class="variable">MyPack</span><span class="operator">;</span>
<span class="keyword">use</span> <span class="variable">Attribute::Handlers</span><span class="operator">;</span>
<span class="keyword">sub</span><span class="variable"> Wolf :ATTR</span><span class="operator">(</span>SCALAR<span class="operator">)</span> <span class="operator">{</span> <span class="keyword">print</span> <span class="string">"howl!\n"</span> <span class="operator">}</span>
</pre>
<pre>
<span class="comment"># later, in some package using or inheriting from MyPack...</span>
</pre>
<pre>
<span class="keyword">my</span> <span class="variable">MyPack</span> <span class="variable">$Fluffy</span> <span class="operator">:</span> <span class="variable">Wolf</span><span class="operator">;</span> <span class="comment"># the attribute handler Wolf will be called</span>
</pre>
<p>Both variables and routines can have attribute handlers. Handlers can
be specific to type (SCALAR, ARRAY, HASH, or CODE), or specific to the
exact compilation phase (BEGIN, CHECK, INIT, or END).
See <a href="../../lib/Attribute/Handlers.html">the Attribute::Handlers manpage</a>.</p>
</li>
<li>
<p><code>B::Concise</code>, by Stephen McCamant, is a new compiler backend for
walking the Perl syntax tree, printing concise info about ops.
The output is highly customisable. See <a href="../../lib/B/Concise.html">the B::Concise manpage</a>. [561+]</p>
</li>
<li>
<p>The new bignum, bigint, and bigrat pragmas, by Tels, implement
transparent bignum support (using the Math::BigInt, Math::BigFloat,
and Math::BigRat backends).</p>
</li>
<li>
<p><code>Class::ISA</code>, by Sean Burke, is a module for reporting the search
path for a class's ISA tree. See <a href="../../lib/Class/ISA.html">the Class::ISA manpage</a>.</p>
</li>
<li>
<p><code>Cwd</code> now has a split personality: if possible, an XS extension is
used, (this will hopefully be faster, more secure, and more robust)
but if not possible, the familiar Perl implementation is used.</p>
</li>
<li>
<p><code>Devel::PPPort</code>, originally by Kenneth Albanowski and now
maintained by Paul Marquess, has been added. It is primarily used
by <code>h2xs</code> to enhance portability of XS modules between different
versions of Perl. See <a href="../../lib/Devel/PPPort.html">the Devel::PPPort manpage</a>.</p>
</li>
<li>
<p><code>Digest</code>, frontend module for calculating digests (checksums), from
Gisle Aas, has been added. See <a href="../../lib/Digest.html">the Digest manpage</a>.</p>
</li>
<li>
<p><code>Digest::MD5</code> for calculating MD5 digests (checksums) as defined in
RFC 1321, from Gisle Aas, has been added. See <a href="../../lib/Digest/MD5.html">the Digest::MD5 manpage</a>.</p>
<pre>
<span class="keyword">use</span> <span class="variable">Digest::MD5</span> <span class="string">'md5_hex'</span><span class="operator">;</span>
</pre>
<pre>
<span class="variable">$digest</span> <span class="operator">=</span> <span class="variable">md5_hex</span><span class="operator">(</span><span class="string">"Thirsty Camel"</span><span class="operator">);</span>
</pre>
<pre>
<span class="keyword">print</span> <span class="variable">$digest</span><span class="operator">,</span> <span class="string">"\n"</span><span class="operator">;</span> <span class="comment"># 01d19d9d2045e005c3f1b80e8b164de1</span>
</pre>
<p>NOTE: the <code>MD5</code> backward compatibility module is deliberately not
included since its further use is discouraged.</p>
<p>See also <a href="../../lib/PerlIO/via/QuotedPrint.html">the PerlIO::via::QuotedPrint manpage</a>.</p>
</li>
<li>
<p><code>Encode</code>, originally by Nick Ing-Simmons and now maintained by Dan
Kogai, provides a mechanism to translate between different character
encodings. Support for Unicode, ISO-8859-1, and ASCII are compiled in
to the module. Several other encodings (like the rest of the
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?