perl5005delta.html
来自「perl教程」· HTML 代码 · 共 1,169 行 · 第 1/5 页
HTML
1,169 行
<p>Perl has a new Social Contract for contributors. See <em>Porting/Contract</em>.</p>
<p>The license included in much of the Perl documentation has changed.
Most of the Perl documentation was previously under the implicit GNU
General Public License or the Artistic License (at the user's choice).
Now much of the documentation unambiguously states the terms under which
it may be distributed. Those terms are in general much less restrictive
than the GNU GPL. See <a href="../../lib/Pod/perl.html">the perl manpage</a> and the individual perl manpages listed
therein.</p>
<p>
</p>
<hr />
<h1><a name="core_changes">Core Changes</a></h1>
<p>
</p>
<h2><a name="threads">Threads</a></h2>
<p>WARNING: Threading is considered an <strong>experimental</strong> feature. Details of the
implementation may change without notice. There are known limitations
and some bugs. These are expected to be fixed in future versions.</p>
<p>See <em>README.threads</em>.</p>
<p>
</p>
<h2><a name="compiler">Compiler</a></h2>
<p>WARNING: The Compiler and related tools are considered <strong>experimental</strong>.
Features may change without notice, and there are known limitations
and bugs. Since the compiler is fully external to perl, the default
configuration will build and install it.</p>
<p>The Compiler produces three different types of transformations of a
perl program. The C backend generates C code that captures perl's state
just before execution begins. It eliminates the compile-time overheads
of the regular perl interpreter, but the run-time performance remains
comparatively the same. The CC backend generates optimized C code
equivalent to the code path at run-time. The CC backend has greater
potential for big optimizations, but only a few optimizations are
implemented currently. The Bytecode backend generates a platform
independent bytecode representation of the interpreter's state
just before execution. Thus, the Bytecode back end also eliminates
much of the compilation overhead of the interpreter.</p>
<p>The compiler comes with several valuable utilities.</p>
<p><code>B::Lint</code> is an experimental module to detect and warn about suspicious
code, especially the cases that the <a href="../../lib/Pod/perlrun.html#item__2dw"><code>-w</code></a> switch does not detect.</p>
<p><code>B::Deparse</code> can be used to demystify perl code, and understand
how perl optimizes certain constructs.</p>
<p><code>B::Xref</code> generates cross reference reports of all definition and use
of variables, subroutines and formats in a program.</p>
<p><code>B::Showlex</code> show the lexical variables used by a subroutine or file
at a glance.</p>
<p><code>perlcc</code> is a simple frontend for compiling perl.</p>
<p>See <code>ext/B/README</code>, <a href="../../lib/B.html">the B manpage</a>, and the respective compiler modules.</p>
<p>
</p>
<h2><a name="regular_expressions">Regular Expressions</a></h2>
<p>Perl's regular expression engine has been seriously overhauled, and
many new constructs are supported. Several bugs have been fixed.</p>
<p>Here is an itemized summary:</p>
<dl>
<dt><strong><a name="item_many_new_and_improved_optimizations">Many new and improved optimizations</a></strong>
<dd>
<p>Changes in the RE engine:</p>
</dd>
<dd>
<pre>
<span class="variable">Unneeded</span> <span class="variable">nodes</span> <span class="variable">removed</span><span class="operator">;</span>
<span class="variable">Substrings</span> <span class="variable">merged</span> <span class="variable">together</span><span class="operator">;</span>
<span class="variable">New</span> <span class="variable">types</span> <span class="variable">of</span> <span class="variable">nodes</span> <span class="variable">to</span> <span class="variable">process</span> <span class="operator">(</span><span class="variable">SUBEXPR</span><span class="operator">)*</span> <span class="keyword">and</span> <span class="variable">similar</span> <span class="variable">expressions</span>
<span class="variable">quickly</span><span class="operator">,</span> <span class="variable">used</span> <span class="keyword">if</span> <span class="variable">the</span> <span class="variable">SUBEXPR</span> <span class="variable">has</span> <span class="keyword">no</span> <span class="variable">side</span> <span class="variable">effects</span> <span class="keyword">and</span> <span class="variable">matches</span>
<span class="variable">strings</span> <span class="variable">of</span> <span class="variable">the</span> <span class="variable">same</span> <span class="keyword">length</span><span class="operator">;</span>
<span class="variable">Better</span> <span class="variable">optimizations</span> <span class="variable">by</span> <span class="variable">lookup</span> <span class="keyword">for</span> <span class="variable">constant</span> <span class="variable">substrings</span><span class="operator">;</span>
<span class="variable">Better</span> <span class="variable">search</span> <span class="keyword">for</span> <span class="variable">constants</span> <span class="variable">substrings</span> <span class="variable">anchored</span> <span class="variable">by</span> <span class="operator">$ ;</span>
</pre>
</dd>
<dd>
<p>Changes in Perl code using RE engine:</p>
</dd>
<dd>
<pre>
<span class="variable">More</span> <span class="variable">optimizations</span> <span class="variable">to</span> <span class="regex">s/longer/short/</span><span class="operator">;</span>
<span class="keyword">study</span><span class="operator">()</span> <span class="variable">was</span> <span class="keyword">not</span> <span class="variable">working</span><span class="operator">;</span>
<span class="regex">/blah/</span> <span class="variable">may</span> <span class="variable">be</span> <span class="variable">optimized</span> <span class="variable">to</span> <span class="variable">an</span> <span class="variable">analogue</span> <span class="variable">of</span> <span class="keyword">index</span><span class="operator">()</span> <span class="keyword">if</span> <span class="variable">$&</span> <span class="variable">$`</span> <span class="variable">$'</span> <span class="keyword">not</span> <span class="variable">seen</span><span class="operator">;</span>
<span class="variable">Unneeded</span> <span class="variable">copying</span> <span class="variable">of</span> <span class="variable">matched</span><span class="operator">-</span><span class="variable">against</span> <span class="variable">string</span> <span class="variable">removed</span><span class="operator">;</span>
<span class="variable">Only</span> <span class="variable">matched</span> <span class="variable">part</span> <span class="variable">of</span> <span class="variable">the</span> <span class="variable">string</span> <span class="variable">is</span> <span class="variable">copying</span> <span class="keyword">if</span> <span class="variable">$`</span> <span class="variable">$'</span> <span class="variable">were</span> <span class="keyword">not</span> <span class="variable">seen</span><span class="operator">;</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_many_bug_fixes">Many bug fixes</a></strong>
<dd>
<p>Note that only the major bug fixes are listed here. See <em>Changes</em> for others.</p>
</dd>
<dd>
<pre>
<span class="variable">Backtracking</span> <span class="variable">might</span> <span class="keyword">not</span> <span class="variable">restore</span> <span class="variable">start</span> <span class="variable">of</span> <span class="variable">$3</span><span class="operator">.</span>
<span class="variable">No</span> <span class="variable">feedback</span> <span class="keyword">if</span> <span class="variable">max</span> <span class="variable">count</span> <span class="keyword">for</span> <span class="operator">*</span> <span class="keyword">or</span> <span class="operator">+</span> <span class="variable">on</span> <span class="string">"complex"</span> <span class="variable">subexpression</span>
<span class="variable">was</span> <span class="variable">reached</span><span class="operator">,</span> <span class="variable">similarly</span> <span class="operator">(</span><span class="variable">but</span> <span class="variable">at</span> <span class="variable">compile</span> <span class="keyword">time</span><span class="operator">)</span> <span class="keyword">for</span> <span class="operator">{</span><span class="number">3</span><span class="operator">,</span><span class="number">34567</span><span class="operator">}</span>
<span class="variable">Primitive</span> <span class="variable">restrictions</span> <span class="variable">on</span> <span class="variable">max</span> <span class="variable">count</span> <span class="variable">introduced</span> <span class="variable">to</span> <span class="variable">decrease</span> <span class="variable">a</span>
<span class="variable">possibility</span> <span class="variable">of</span> <span class="variable">a</span> <span class="variable">segfault</span><span class="operator">;</span>
<span class="operator">(</span><span class="variable">ZERO</span><span class="operator">-</span><span class="variable">LENGTH</span><span class="operator">)*</span> <span class="variable">could</span> <span class="variable">segfault</span><span class="operator">;</span>
<span class="operator">(</span><span class="variable">ZERO</span><span class="operator">-</span><span class="variable">LENGTH</span><span class="operator">)*</span> <span class="variable">was</span> <span class="variable">prohibited</span><span class="operator">;</span>
<span class="variable">Long</span> <span class="variable">REs</span> <span class="variable">were</span> <span class="keyword">not</span> <span class="variable">allowed</span><span class="operator">;</span>
<span class="regex">/RE/g</span> <span class="variable">could</span> <span class="variable">skip</span> <span class="variable">matches</span> <span class="variable">at</span> <span class="variable">the</span> <span class="variable">same</span> <span class="variable">position</span> <span class="variable">after</span> <span class="variable">a</span>
<span class="variable">zero</span><span class="operator">-</span><span class="keyword">length</span> <span class="variable">match</span><span class="operator">;</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_new_regular_expression_constructs">New regular expression constructs</a></strong>
<dd>
<p>The following new syntax elements are supported:</p>
</dd>
<dd>
<pre>
(?<=RE)
(?<!RE)
(?{ CODE })
(?i-x)
(?i:RE)
(?(COND)YES_RE|NO_RE)
(?>RE)
\z</pre>
</dd>
</li>
<dt><strong><a name="item_new_operator_for_precompiled_regular_expressions">New operator for precompiled regular expressions</a></strong>
<dd>
<p>See <a href="#new_c_qre_sol_e_sol___operator">New <a href="../../lib/Pod/perlfunc.html#item_qr_"><code>qr//</code></a> operator</a>.</p>
</dd>
</li>
<dt><strong><a name="item_other_improvements">Other improvements</a></strong>
<dd>
<pre>
Better debugging output (possibly with colors),
even from non-debugging Perl;
RE engine code now looks like C, not like assembler;
Behaviour of RE modifiable by `use re' directive;
Improved documentation;
Test suite significantly extended;
Syntax [:^upper:] etc., reserved inside character classes;</pre>
</dd>
<dt><strong><a name="item_incompatible_changes">Incompatible changes</a></strong>
<dd>
<pre>
(?i) localized inside enclosing group;
$( is not interpolated into RE any more;
/RE/g may match at the same position (with non-zero length)
after a zero-length match (bug fix).</pre>
</dd>
</dl>
<p>See <a href="../../lib/Pod/perlre.html">the perlre manpage</a> and <a href="../../lib/Pod/perlop.html">the perlop manpage</a>.</p>
<p>
</p>
<h2><a name="improved_malloc__">Improved <code>malloc()</code></a></h2>
<p>See banner at the beginning of <code>malloc.c</code> for details.</p>
<p>
</p>
<h2><a name="quicksort_is_internally_implemented">Quicksort is internally implemented</a></h2>
<p>Perl now contains its own highly optimized <code>qsort()</code> routine. The new <code>qsort()</code>
is resistant to inconsistent comparison functions, so Perl's <a href="../../lib/Pod/perlfunc.html#item_sort"><code>sort()</code></a> will
not provoke coredumps any more when given poorly written sort subroutines.
(Some C library <code>qsort()</code>s that were being used before used to have this
problem.) In our testing, the new <code>qsort()</code> required the minimal number
of pair-wise compares on average, among all known <code>qsort()</code> implementations.</p>
<p>See <code>perlfunc/sort</code>.</p>
<p>
</p>
<h2><a name="reliable_signals">Reliable signals</a></h2>
<p>Perl's signal handling is susceptible to random crashes, because signals
arrive asynchronously, and the Perl runtime is not reentrant at arbitrary
times.</p>
<p>However, one experimental implementation of reliable signals is available
when threads are enabled. See <code>Thread::Signal</code>. Also see <em>INSTALL</em> for
how to build a Perl capable of threads.</p>
<p>
</p>
<h2><a name="reliable_stack_pointers">Reliable stack pointers</a></h2>
<p>The internals now reallocate the perl stack only at predictable times.
In particular, magic calls never trigger reallocations of the stack,
because all reentrancy of the runtime is handled using a "stack of stacks".
This should improve reliability of cached stack pointers in the internals
and in XSUBs.</p>
<p>
</p>
<h2><a name="more_generous_treatment_of_carriage_returns">More generous treatment of carriage returns</a></h2>
<p>Perl used to complain if it encountered literal carriage returns in
scripts. Now they are mostly treated like whitespace within program text.
Inside string literals and here documents, literal carriage returns are
ignored if they occur paired with linefeeds, or get interpreted as whitespace
if they stand alone. This behavior means that literal carriage returns
in files should be avoided. You can get the older, more compatible (but
less generous) behavior by defining the preprocessor symbol
<code>PERL_STRICT_CR</code> when building perl. Of course, all this has nothing
whatever to do with how escapes like <code>\r</code> are handled within strings.</p>
<p>Note that this doesn't somehow magically allow you to keep all text files
in DOS format. The generous treatment only applies to files that perl
itself parses. If your C compiler doesn't allow carriage returns in
files, you may still be unable to build modules that need a C compiler.</p>
<p>
</p>
<h2><a name="memory_leaks">Memory leaks</a></h2>
<p><a href="../../lib/Pod/perlvar.html#item_substr"><code>substr</code></a>, <a href="../../lib/Pod/perlfunc.html#item_pos"><code>pos</code></a> and <a href="../../lib/Pod/perlfunc.html#item_vec"><code>vec</code></a> don't leak memory anymore when used in lvalue
context. Many small leaks that impacted applications that embed multiple
interpreters have been fixed.</p>
<p>
</p>
<h2><a name="better_support_for_multiple_interpreters">Better support for multiple interpreters</a></h2>
<p>The build-time option <code>-DMULTIPLICITY</code> has had many of the details
reworked. Some previously global variables that should have been
per-interpreter now are. With care, this allows interpreters to call
each other. See the <code>PerlInterp</code> extension on CPAN.</p>
<p>
</p>
<h2><a name="behavior_of_local___on_array_and_hash_elements_is_now_welldefined">Behavior of <a href="../../lib/Pod/perlfunc.html#item_local"><code>local()</code></a> on array and hash elements is now well-defined</a></h2>
<p>See <a href="../../lib/Pod/perlsub.html#temporary_values_via_local__">Temporary Values via local() in the perlsub manpage</a>.</p>
<p>
</p>
<h2><a name="___is_transparently_tied_to_the_errno_module"><a href="../../lib/Pod/perlvar.html#item___"><code>%!</code></a> is transparently tied to the <a href="../../lib/Errno.html">the Errno manpage</a> module</a></h2>
<p>See <a href="../../lib/Pod/perlvar.html">the perlvar manpage</a>, and <a href="../../lib/Errno.html">the Errno manpage</a>.</p>
<p>
</p>
<h2><a name="pseudohashes_are_supported">Pseudo-hashes are supported</a></h2>
<p>See <a href="../../lib/Pod/perlref.html">the perlref manpage</a>.</p>
<p>
</p>
<h2><a name="expr_foreach_expr_is_supported"><code>EXPR foreach EXPR</code> is supported</a></h2>
<p>See <a href="../../lib/Pod/perlsyn.html">the perlsyn manpage</a>.</p>
<p>
</p>
<h2><a name="keywords_can_be_globally_overridden">Keywords can be globally overridden</a></h2>
<p>See <a href="../../lib/Pod/perlsub.html">the perlsub manpage</a>.</p>
<p>
</p>
<h2><a name="__e_is_meaningful_on_win32"><a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a> is meaningful on Win32</a></h2>
<p>See <a href="../../lib/Pod/perlvar.html">the perlvar manpage</a>.</p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?