perl56delta.html

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

HTML
975
字号
<h1><a name="name">NAME</a></h1>
<p>perl56delta - what's new for perl v5.6.0</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This document describes differences between the 5.005 release and the 5.6.0
release.</p>
<p>
</p>
<hr />
<h1><a name="core_enhancements">Core Enhancements</a></h1>
<p>
</p>
<h2><a name="interpreter_cloning__threads__and_concurrency">Interpreter cloning, threads, and concurrency</a></h2>
<p>Perl 5.6.0 introduces the beginnings of support for running multiple
interpreters concurrently in different threads.  In conjunction with
the <code>perl_clone()</code> API call, which can be used to selectively duplicate
the state of any given interpreter, it is possible to compile a
piece of code once in an interpreter, clone that interpreter
one or more times, and run all the resulting interpreters in distinct
threads.</p>
<p>On the Windows platform, this feature is used to emulate <a href="../../lib/Pod/perlfunc.html#item_fork"><code>fork()</code></a> at the
interpreter level.  See <a href="../../lib/Pod/perlfork.html">the perlfork manpage</a> for details about that.</p>
<p>This feature is still in evolution.  It is eventually meant to be used
to selectively clone a subroutine and data reachable from that
subroutine in a separate interpreter and run the cloned subroutine
in a separate thread.  Since there is no shared data between the
interpreters, little or no locking will be needed (unless parts of
the symbol table are explicitly shared).  This is obviously intended
to be an easy-to-use replacement for the existing threads support.</p>
<p>Support for cloning interpreters and interpreter concurrency can be
enabled using the -Dusethreads Configure option (see win32/Makefile for
how to enable it on Windows.)  The resulting perl executable will be
functionally identical to one that was built with -Dmultiplicity, but
the <code>perl_clone()</code> API call will only be available in the former.</p>
<p>-Dusethreads enables the cpp macro USE_ITHREADS by default, which in turn
enables Perl source code changes that provide a clear separation between
the op tree and the data it operates with.  The former is immutable, and
can therefore be shared between an interpreter and all of its clones,
while the latter is considered local to each interpreter, and is therefore
copied for each clone.</p>
<p>Note that building Perl with the -Dusemultiplicity Configure option
is adequate if you wish to run multiple <strong>independent</strong> interpreters
concurrently in different threads.  -Dusethreads only provides the
additional functionality of the <code>perl_clone()</code> API call and other
support for running <strong>cloned</strong> interpreters concurrently.</p>
<pre>
    NOTE: This is an experimental feature.  Implementation details are
    subject to change.</pre>
<p>
</p>
<h2><a name="lexically_scoped_warning_categories">Lexically scoped warning categories</a></h2>
<p>You can now control the granularity of warnings emitted by perl at a finer
level using the <code>use warnings</code> pragma.  <a href="../../lib/warnings.html">the warnings manpage</a> and <a href="../../lib/Pod/perllexwarn.html">the perllexwarn manpage</a>
have copious documentation on this feature.</p>
<p>
</p>
<h2><a name="unicode_and_utf8_support">Unicode and UTF-8 support</a></h2>
<p>Perl now uses UTF-8 as its internal representation for character
strings.  The <code>utf8</code> and <code>bytes</code> pragmas are used to control this support
in the current lexical scope.  See <a href="../../lib/Pod/perlunicode.html">the perlunicode manpage</a>, <a href="../../lib/utf8.html">the utf8 manpage</a> and <a href="../../lib/bytes.html">the bytes manpage</a> for
more information.</p>
<p>This feature is expected to evolve quickly to support some form of I/O
disciplines that can be used to specify the kind of input and output data
(bytes or characters).  Until that happens, additional modules from CPAN
will be needed to complete the toolkit for dealing with Unicode.</p>
<pre>
    NOTE: This should be considered an experimental feature.  Implementation
    details are subject to change.</pre>
<p>
</p>
<h2><a name="support_for_interpolating_named_characters">Support for interpolating named characters</a></h2>
<p>The new <code>\N</code> escape interpolates named characters within strings.
For example, <code>&quot;Hi! \N{WHITE SMILING FACE}&quot;</code> evaluates to a string
with a unicode smiley face at the end.</p>
<p>
</p>
<h2><a name="our_declarations">&quot;our&quot; declarations</a></h2>
<p>An &quot;our&quot; declaration introduces a value that can be best understood
as a lexically scoped symbolic alias to a global variable in the
package that was current where the variable was declared.  This is
mostly useful as an alternative to the <code>vars</code> pragma, but also provides
the opportunity to introduce typing and other attributes for such
variables.  See <a href="../../lib/Pod/perlfunc.html#our">our in the perlfunc manpage</a>.</p>
<p>
</p>
<h2><a name="support_for_strings_represented_as_a_vector_of_ordinals">Support for strings represented as a vector of ordinals</a></h2>
<p>Literals of the form <code>v1.2.3.4</code> are now parsed as a string composed
of characters with the specified ordinals.  This is an alternative, more
readable way to construct (possibly unicode) strings instead of
interpolating characters, as in <code>&quot;\x{1}\x{2}\x{3}\x{4}&quot;</code>.  The leading
<code>v</code> may be omitted if there are more than two ordinals, so <code>1.2.3</code> is
parsed the same as <code>v1.2.3</code>.</p>
<p>Strings written in this form are also useful to represent version &quot;numbers&quot;.
It is easy to compare such version &quot;numbers&quot; (which are really just plain
strings) using any of the usual string comparison operators <code>eq</code>, <code>ne</code>,
<code>lt</code>, <code>gt</code>, etc., or perform bitwise string operations on them using <code>|</code>,
<code>&amp;</code>, etc.</p>
<p>In conjunction with the new <a href="../../lib/Pod/perlvar.html#item___v"><code>$^V</code></a> magic variable (which contains
the perl version as a string), such literals can be used as a readable way
to check if you're running a particular version of Perl:</p>
<pre>
    <span class="comment"># this will parse in older versions of Perl also</span>
    <span class="keyword">if</span> <span class="operator">(</span><span class="variable">$^V</span> <span class="keyword">and</span> <span class="variable">$^V</span> <span class="keyword">gt</span> <span class="variable">v5</span><span class="number">.6</span><span class="operator">.</span><span class="number">0</span><span class="operator">)</span> <span class="operator">{</span>
        <span class="comment"># new features supported</span>
    <span class="operator">}</span>
</pre>
<p><a href="../../lib/Pod/perlfunc.html#item_require"><code>require</code></a> and <a href="../../lib/Pod/perlfunc.html#item_use"><code>use</code></a> also have some special magic to support such
literals, but this particular usage should be avoided because it leads to
misleading error messages under versions of Perl which don't support vector
strings.  Using a true version number will ensure correct behavior in all
versions of Perl:</p>
<pre>
    <span class="keyword">require</span> <span class="number">5.006</span><span class="operator">;</span>    <span class="comment"># run time check for v5.6</span>
    <span class="keyword">use</span> <span class="number">5.006_001</span><span class="operator">;</span>    <span class="comment"># compile time check for v5.6.1</span>
</pre>
<p>Also, <a href="../../lib/Pod/perlfunc.html#item_sprintf"><code>sprintf</code></a> and <a href="../../lib/Pod/perlfunc.html#item_printf"><code>printf</code></a> support the Perl-specific format flag <code>%v</code>
to print ordinals of characters in arbitrary strings:</p>
<pre>
    <span class="keyword">printf</span> <span class="string">"v%vd"</span><span class="operator">,</span> <span class="variable">$^V</span><span class="operator">;</span>         <span class="comment"># prints current version, such as "v5.5.650"</span>
    <span class="keyword">printf</span> <span class="string">"%*vX"</span><span class="operator">,</span> <span class="string">":"</span><span class="operator">,</span> <span class="variable">$addr</span><span class="operator">;</span>  <span class="comment"># formats IPv6 address</span>
    <span class="keyword">printf</span> <span class="string">"%*vb"</span><span class="operator">,</span> <span class="string">" "</span><span class="operator">,</span> <span class="variable">$bits</span><span class="operator">;</span>  <span class="comment"># displays bitstring</span>
</pre>
<p>See <a href="../../lib/Pod/perldata.html#scalar_value_constructors">Scalar value constructors in the perldata manpage</a> for additional information.</p>
<p>
</p>
<h2><a name="improved_perl_version_numbering_system">Improved Perl version numbering system</a></h2>
<p>Beginning with Perl version 5.6.0, the version number convention has been
changed to a &quot;dotted integer&quot; scheme that is more commonly found in open
source projects.</p>
<p>Maintenance versions of v5.6.0 will be released as v5.6.1, v5.6.2 etc.
The next development series following v5.6.0 will be numbered v5.7.x,
beginning with v5.7.0, and the next major production release following
v5.6.0 will be v5.8.0.</p>
<p>The English module now sets $PERL_VERSION to $^V (a string value) rather
than <a href="../../lib/Pod/perlvar.html#item___"><code>$]</code></a> (a numeric value).  (This is a potential incompatibility.
Send us a report via perlbug if you are affected by this.)</p>
<p>The v1.2.3 syntax is also now legal in Perl.
See <a href="#support_for_strings_represented_as_a_vector_of_ordinals">Support for strings represented as a vector of ordinals</a> for more on that.</p>
<p>To cope with the new versioning system's use of at least three significant
digits for each version component, the method used for incrementing the
subversion number has also changed slightly.  We assume that versions older
than v5.6.0 have been incrementing the subversion component in multiples of
10.  Versions after v5.6.0 will increment them by 1.  Thus, using the new
notation, 5.005_03 is the &quot;same&quot; as v5.5.30, and the first maintenance
version following v5.6.0 will be v5.6.1 (which should be read as being
equivalent to a floating point value of 5.006_001 in the older format,
stored in <a href="../../lib/Pod/perlvar.html#item___"><code>$]</code></a>).</p>
<p>
</p>
<h2><a name="new_syntax_for_declaring_subroutine_attributes">New syntax for declaring subroutine attributes</a></h2>
<p>Formerly, if you wanted to mark a subroutine as being a method call or
as requiring an automatic <a href="../../lib/Pod/perlfunc.html#item_lock"><code>lock()</code></a> when it is entered, you had to declare
that with a <code>use attrs</code> pragma in the body of the subroutine.
That can now be accomplished with declaration syntax, like this:</p>
<pre>
    <span class="keyword">sub</span><span class="variable"> mymethod : locked method</span><span class="operator">;</span>
    <span class="operator">...</span>
    <span class="keyword">sub</span><span class="variable"> mymethod : locked method </span><span class="operator">{</span>
        <span class="operator">...</span>
    <span class="operator">}</span>
</pre>
<pre>
    <span class="keyword">sub</span><span class="variable"> othermethod :locked :method</span><span class="operator">;</span>
    <span class="operator">...</span>
    <span class="keyword">sub</span><span class="variable"> othermethod :locked :method </span><span class="operator">{</span>
        <span class="operator">...</span>
    <span class="operator">}</span>
</pre>
<p>(Note how only the first <code>:</code> is mandatory, and whitespace surrounding
the <code>:</code> is optional.)</p>
<p><em>AutoSplit.pm</em> and <em>SelfLoader.pm</em> have been updated to keep the attributes
with the stubs they provide.  See <a href="../../lib/attributes.html">the attributes manpage</a>.</p>
<p>
</p>
<h2><a name="file_and_directory_handles_can_be_autovivified">File and directory handles can be autovivified</a></h2>
<p>Similar to how constructs such as <code>$x-&gt;[0]</code> autovivify a reference,
handle constructors (open(), opendir(), pipe(), socketpair(), sysopen(),
socket(), and <a href="../../lib/Pod/perlfunc.html#item_accept"><code>accept())</code></a> now autovivify a file or directory handle
if the handle passed to them is an uninitialized scalar variable.  This
allows the constructs such as <a href="#item_open"><code>open(my $fh, ...)</code></a> and <a href="#item_open"><code>open(local $fh,...)</code></a>
to be used to create filehandles that will conveniently be closed
automatically when the scope ends, provided there are no other references
to them.  This largely eliminates the need for typeglobs when opening
filehandles that must be passed around, as in the following example:</p>
<pre>
    <span class="keyword">sub</span><span class="variable"> myopen </span><span class="operator">{</span>
        <span class="keyword">open</span> <span class="keyword">my</span> <span class="variable">$fh</span><span class="operator">,</span> <span class="string">"@_"</span>
             <span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Can't open '@_': $!"</span><span class="operator">;</span>
        <span class="keyword">return</span> <span class="variable">$fh</span><span class="operator">;</span>
    <span class="operator">}</span>
</pre>
<pre>
    <span class="operator">{</span>

⌨️ 快捷键说明

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