perl561delta.html
来自「perl教程」· HTML 代码 · 共 1,261 行 · 第 1/5 页
HTML
1,261 行
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 "same" 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->[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>
<span class="keyword">my</span> <span class="variable">$f</span> <span class="operator">=</span> <span class="variable">myopen</span><span class="operator">(</span><span class="string">"</etc/motd"</span><span class="operator">);</span>
<span class="keyword">print</span> <span class="operator"><</span><span class="variable">$f</span><span class="operator">>;</span>
<span class="comment"># $f implicitly closed here</span>
<span class="operator">}</span>
</pre>
<p>
</p>
<h2><a name="open___with_more_than_two_arguments"><a href="#item_open"><code>open()</code></a> with more than two arguments</a></h2>
<p>If <a href="#item_open"><code>open()</code></a> is passed three arguments instead of two, the second argument
is used as the mode and the third argument is taken to be the file name.
This is primarily useful for protecting against unintended magic behavior
of the traditional two-argument form. See <a href="../../lib/Pod/perlfunc.html#open">open in the perlfunc manpage</a>.</p>
<p>
</p>
<h2><a name="64bit_support">64-bit support</a></h2>
<p>Any platform that has 64-bit integers either</p>
<pre>
(1) natively as longs or ints
(2) via special compiler flags
(3) using long long or int64_t</pre>
<p>is able to use "quads" (64-bit integers) as follows:</p>
<ul>
<li>
<p>constants (decimal, hexadecimal, octal, binary) in the code</p>
</li>
<li>
<p>arguments to <a href="../../lib/Pod/perlfunc.html#item_oct"><code>oct()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_hex"><code>hex()</code></a></p>
</li>
<li>
<p>arguments to print(), <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> (flag prefixes ll, L, q)</p>
</li>
<li>
<p>printed as such</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack()</code></a> "q" and "Q" formats</p>
</li>
<li>
<p>in basic arithmetics: + - * / % (NOTE: operating close to the limits
of the integer values may produce surprising results)</p>
</li>
<li>
<p>in bit arithmetics: & | ^ ~ << >> (NOTE: these used to be forced
to be 32 bits wide but now operate on the full native width.)</p>
</li>
<li>
<p><a href="#item_vec"><code>vec()</code></a></p>
</li>
</ul>
<p>Note that unless you have the case (a) you will have to configure
and compile Perl using the -Duse64bitint Configure flag.</p>
<pre>
NOTE: The Configure flags -Duselonglong and -Duse64bits have been
deprecated. Use -Duse64bitint instead.</pre>
<p>There are actually two modes of 64-bitness: the first one is achieved
using Configure -Duse64bitint and the second one using Configure
-Duse64bitall. The difference is that the first one is minimal and
the second one maximal. The first works in more places than the second.</p>
<p>The <code>use64bitint</code> does only as much as is required to get 64-bit
integers into Perl (this may mean, for example, using "long longs")
while your memory may still be limited to 2 gigabytes (because your
pointers could still be 32-bit). Note that the name <code>64bitint</code> does
not imply that your C compiler will be using 64-bit <a href="../../lib/Pod/perlfunc.html#item_int"><code>int</code></a>s (it might,
but it doesn't have to): the <code>use64bitint</code> means that you will be
able to have 64 bits wide scalar values.</p>
<p>The <code>use64bitall</code> goes all the way by attempting to switch also
integers (if it can), longs (and pointers) to being 64-bit. This may
create an even more binary incompatible Perl than -Duse64bitint: the
resulting executable may not run at all in a 32-bit box, or you may
have to reboot/reconfigure/rebuild your operating system to be 64-bit
aware.</p>
<p>Natively 64-bit systems like Alpha and Cray need neither -Duse64bitint
nor -Duse64bitall.</p>
<p>Last but not least: note that due to Perl's habit of always using
floating point numbers, the quads are still not true integers.
When quads overflow their limits (0...18_446_744_073_709_551_615 unsigned,
-9_223_372_036_854_775_808...9_223_372_036_854_775_807 signed), they
are silently promoted to floating point numbers, after which they will
start losing precision (in their lower digits).</p>
<pre>
NOTE: 64-bit support is still experimental on most platforms.
Existing support only covers the LP64 data model. In particular, the
LLP64 data model is not yet supported. 64-bit libraries and system
APIs on many platforms have not stabilized--your mileage may vary.</pre>
<p>
</p>
<h2><a name="large_file_support">Large file support</a></h2>
<p>If you have filesystems that support "large files" (files larger than
2 gigabytes), you may now also be able to create and access them from
Perl.</p>
<pre>
NOTE: The default action is to enable large file support, if
available on the platform.</pre>
<p>If the large file support is on, and you have a Fcntl constant
O_LARGEFILE, the O_LARGEFILE is automatically added to the flags
of sysopen().</p>
<p>Beware that unless your filesystem also supports "sparse files" seeking
to umpteen petabytes may be inadvisable.</p>
<p>Note that in addition to requiring a proper file system to do large
files you may also need to adjust your per-process (or your
per-system, or per-process-group, or per-user-group) maximum filesize
limits before running Perl scripts that try to handle large files,
especially if you intend to write such files.</p>
<p>Finally, in addition to your process/process group maximum filesize
limits, you may have quota limits on your filesystems that stop you
(your user id or your user group id) from using large files.</p>
<p>Adjusting your process/user/group/file system/operating system limits
is outside the scope of Perl core language. For process limits, you
may try increasing the limits using your shell's limits/limit/ulimit
command before running Perl. The BSD::Resource extension (not
included with the standard Perl distribution) may also be of use, it
offers the getrlimit/setrlimit interface that can be used to adjust
process resource usage limits, including the maximum filesize limit.</p>
<p>
</p>
<h2><a name="long_doubles">Long doubles</a></h2>
<p>In some systems you may be able to use long doubles to enhance the
range and precision of your double precision floating point numbers
(that is, Perl's numbers). Use Configure -Duselongdouble to enable
this support (if it is available).</p>
<p>
</p>
<h2><a name="more_bits">"more bits"</a></h2>
<p>You can "Configure -Dusemorebits" to turn on both the 64-bit support
and the long double support.</p>
<p>
</p>
<h2><a name="enhanced_support_for_sort___subroutines">Enhanced support for <a href="#item_sort"><code>sort()</code></a> subroutines</a></h2>
<p>Perl subroutines with a prototype of <code>($$)</code>, and XSUBs in general, can
now be used as sort subroutines. In either case, the two elements to
be compared are passed as normal parameters in @_. See <a href="../../lib/Pod/perlfunc.html#sort">sort in the perlfunc manpage</a>.</p>
<p>For unprototyped sort subroutines, the historical behavior of passing
the elements to be compared as the global variables $a and $b remains
unchanged.</p>
<p>
</p>
<h2><a name="sort__coderef__foo_allowed"><code>sort $coderef @foo</code> allowed</a></h2>
<p><a href="#item_sort"><code>sort()</code></a> did not accept a subroutine reference as the comparison
function in earlier versions. This is now permitted.</p>
<p>
</p>
<h2><a name="file_globbing_implemented_internally">File globbing implemented internally</a></h2>
<p>Perl now uses the File::Glob implementation of the <a href="#item_glob"><code>glob()</code></a> operator
automatically. This avoids using an external csh process and the
problems associated with it.</p>
<pre>
NOTE: This is currently an experimental feature. Interfaces and
implementation are subject to change.</pre>
<p>
</p>
<h2><a name="support_for_check_blocks">Support for CHECK blocks</a></h2>
<p>In addition to <code>BEGIN</code>, <code>INIT</code>, <code>END</code>, <code>DESTROY</code> and <code>AUTOLOAD</code>,
subroutines named <code>CHECK</code> are now special. These are queued up during
compilation and behave similar to END blocks, except they are called at
the end of compilation rather than at the end of execution. They cannot
be called directly.</p>
<p>
</p>
<h2><a name="posix_character_class_syntax_______supported">POSIX character class syntax [: :] supported</a></h2>
<p>For example to match alphabetic characters use /[[:alpha:]]/.
See <a href="../../lib/Pod/perlre.html">the perlre manpage</a> for details.</p>
<p>
</p>
<h2><a name="better_pseudorandom_number_generator">Better pseudo-random number generator</a></h2>
<p>In 5.005_0x and earlier, perl's <a href="../../lib/Pod/perlfunc.html#item_rand"><code>rand()</code></a> function used the C library
<a href="../../lib/Pod/perlfunc.html#item_rand"><code>rand(3)</code></a> function. As of 5.005_52, Configure tests for drand48(),
random(), and <a href="../../lib/Pod/perlfunc.html#item_rand"><code>rand()</code></a> (in that order) and picks the first one it finds.</p>
<p>These changes should result in better random numbers from rand().</p>
<p>
</p>
<h2><a name="improved_qw___operator">Improved <a href="../../lib/Pod/perlfunc.html#item_qw_"><code>qw//</code></a> operator</a></h2>
<p>The <a href="../../lib/Pod/perlfunc.html#item_qw_"><code>qw//</code></a> operator is now evaluated at compile time into a true list
instead of being replaced with a run time call to <a href="../../lib/Pod/perlfunc.html#item_split"><code>split()</code></a>. This
removes the confusing misbehaviour of <a href="../../lib/Pod/perlfunc.html#item_qw_"><code>qw//</code></a> in scalar context, which
had inherited that behaviour from split().</p>
<p>Thus:</p>
<pre>
<span class="variable">$foo</span> <span class="operator">=</span> <span class="operator">(</span><span class="variable">$bar</span><span class="operator">)</span> <span class="operator">=</span> <span class="string">qw(a b c)</span><span class="operator">;</span> <span class="keyword">print</span> <span class="string">"$foo|$bar\n"</span><span class="operator">;</span>
</pre>
<p>now correctly prints "3|a", instead of "2|a".</p>
<p>
</p>
<h2><a name="better_worstcase_behavior_of_hashes">Better worst-case behavior of hashes</a></h2>
<p>Small changes in the hashing algorithm have been implemented in
order to improve the distribution of lower order bits in the
hashed value. This is expected to yield better performance on
k
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?