perl58delta.html

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

HTML
1,127 行
字号
<li>
<p>For developers interested in enhancing Perl's Unicode capabilities:
almost all the UCD files are included with the Perl distribution in
the <em>lib/unicore</em> subdirectory.  The most notable omission, for space
considerations, is the Unihan database.</p>
</li>
<li>
<p>The properties \p{Blank} and \p{SpacePerl} have been added. &quot;Blank&quot; is like
C isblank(), that is, it contains only &quot;horizontal whitespace&quot; (the space
character is, the newline isn't), and the &quot;SpacePerl&quot; is the Unicode
equivalent of <code>\s</code> (\p{Space} isn't, since that includes the vertical
tabulator character, whereas <code>\s</code> doesn't.)</p>
<p>See &quot;New Unicode Properties&quot; earlier in this document for additional
information on changes with Unicode properties.</p>
</li>
</ul>
<p>
</p>
<h2><a name="perlio_is_now_the_default">PerlIO is Now The Default</a></h2>
<ul>
<li>
<p>IO is now by default done via PerlIO rather than system's &quot;stdio&quot;.
PerlIO allows &quot;layers&quot; to be &quot;pushed&quot; onto a file handle to alter the
handle's behaviour.  Layers can be specified at open time via 3-arg
form of open:</p>
<pre>
   open($fh,'&gt;:crlf :utf8', $path) || ...</pre>
<p>or on already opened handles via extended <a href="../../lib/Pod/perlfunc.html#item_binmode"><code>binmode</code></a>:</p>
<pre>
   <span class="keyword">binmode</span><span class="operator">(</span><span class="variable">$fh</span><span class="operator">,</span><span class="string">':encoding(iso-8859-7)'</span><span class="operator">);</span>
</pre>
<p>The built-in layers are: unix (low level read/write), stdio (as in
previous Perls), perlio (re-implementation of stdio buffering in a
portable manner), crlf (does CRLF &lt;=&gt; &quot;\n&quot; translation as on Win32,
but available on any platform).  A mmap layer may be available if
platform supports it (mostly UNIXes).</p>
<p>Layers to be applied by default may be specified via the 'open' pragma.</p>
<p>See <a href="#installation_and_configuration_improvements">Installation and Configuration Improvements</a> for the effects
of PerlIO on your architecture name.</p>
</li>
<li>
<p>If your platform supports fork(), you can use the list form of <a href="../../lib/Pod/perlfunc.html#item_open"><code>open</code></a>
for pipes.  For example:</p>
<pre>
    <span class="keyword">open</span> <span class="variable">KID_PS</span><span class="operator">,</span> <span class="string">"-|"</span><span class="operator">,</span> <span class="string">"ps"</span><span class="operator">,</span> <span class="string">"aux"</span> <span class="keyword">or</span> <span class="keyword">die</span> <span class="variable">$!</span><span class="operator">;</span>
</pre>
<p>forks the <code>ps(1)</code> command (without spawning a shell, as there are more
than three arguments to open()), and reads its standard output via the
<code>KID_PS</code> filehandle.  See <a href="../../lib/Pod/perlipc.html">the perlipc manpage</a>.</p>
</li>
<li>
<p>File handles can be marked as accepting Perl's internal encoding of Unicode
(UTF-8 or UTF-EBCDIC depending on platform) by a pseudo layer &quot;:utf8&quot; :</p>
<pre>
   <span class="keyword">open</span><span class="operator">(</span><span class="variable">$fh</span><span class="operator">,</span><span class="string">"&gt;:utf8"</span><span class="operator">,</span><span class="string">"Uni.txt"</span><span class="operator">);</span>
</pre>
<p>Note for EBCDIC users: the pseudo layer &quot;:utf8&quot; is erroneously named
for you since it's not UTF-8 what you will be getting but instead
UTF-EBCDIC.  See <a href="../../lib/Pod/perlunicode.html">the perlunicode manpage</a>, <a href="../../lib/utf8.html">the utf8 manpage</a>, and
<a href="http://www.unicode.org/unicode/reports/tr16/">http://www.unicode.org/unicode/reports/tr16/</a> for more information.
In future releases this naming may change.  See <a href="../../lib/Pod/perluniintro.html">the perluniintro manpage</a>
for more information about UTF-8.</p>
</li>
<li>
<p>If your environment variables (LC_ALL, LC_CTYPE, LANG) look like you
want to use UTF-8 (any of the variables match <code>/utf-?8/i</code>), your
STDIN, STDOUT, STDERR handles and the default open layer (see <a href="../../lib/open.html">the open manpage</a>)
are marked as UTF-8.  (This feature, like other new features that
combine Unicode and I/O, work only if you are using PerlIO, but that's
the default.)</p>
<p>Note that after this Perl really does assume that everything is UTF-8:
for example if some input handle is not, Perl will probably very soon
complain about the input data like this &quot;Malformed UTF-8 ...&quot; since
any old eight-bit data is not legal UTF-8.</p>
<p>Note for code authors: if you want to enable your users to use UTF-8
as their default encoding  but in your code still have eight-bit I/O streams
(such as images or zip files), you need to explicitly <a href="../../lib/Pod/perlfunc.html#item_open"><code>open()</code></a> or <a href="../../lib/Pod/perlfunc.html#item_binmode"><code>binmode()</code></a>
with <a href="../../lib/Pod/perlrun.html#item__3abytes"><code>:bytes</code></a> (see <a href="../../lib/Pod/perlfunc.html#open">open in the perlfunc manpage</a> and <a href="../../lib/Pod/perlfunc.html#binmode">binmode in the perlfunc manpage</a>), or you
can just use <a href="../../lib/Pod/perlfunc.html#item_binmode"><code>binmode(FH)</code></a> (nice for pre-5.8.0 backward compatibility).</p>
</li>
<li>
<p>File handles can translate character encodings from/to Perl's internal
Unicode form on read/write via the &quot;:encoding()&quot; layer.</p>
</li>
<li>
<p>File handles can be opened to &quot;in memory&quot; files held in Perl scalars via:</p>
<pre>
   open($fh,'&gt;', \$variable) || ...</pre>
</li>
<li>
<p>Anonymous temporary files are available without need to
'use FileHandle' or other module via</p>
<pre>
   open($fh,&quot;+&gt;&quot;, undef) || ...</pre>
<p>That is a literal undef, not an undefined value.</p>
</li>
</ul>
<p>
</p>
<h2><a name="ithreads">ithreads</a></h2>
<p>The new interpreter threads (&quot;ithreads&quot; for short) implementation of
multithreading, by Arthur Bergman, replaces the old &quot;5.005 threads&quot;
implementation.  In the ithreads model any data sharing between
threads must be explicit, as opposed to the model where data sharing
was implicit.  See <a href="../../lib/threads.html">the threads manpage</a> and <a href="../../lib/threads/shared.html">the threads::shared manpage</a>, and
<a href="../../lib/Pod/perlthrtut.html">the perlthrtut manpage</a>.</p>
<p>As a part of the ithreads implementation Perl will also use
any necessary and detectable reentrant libc interfaces.</p>
<p>
</p>
<h2><a name="restricted_hashes">Restricted Hashes</a></h2>
<p>A restricted hash is restricted to a certain set of keys, no keys
outside the set can be added.  Also individual keys can be restricted
so that the key cannot be deleted and the value cannot be changed.
No new syntax is involved: the Hash::Util module is the interface.</p>
<p>
</p>
<h2><a name="safe_signals">Safe Signals</a></h2>
<p>Perl used to be fragile in that signals arriving at inopportune moments
could corrupt Perl's internal state.  Now Perl postpones handling of
signals until it's safe (between opcodes).</p>
<p>This change may have surprising side effects because signals no longer
interrupt Perl instantly.  Perl will now first finish whatever it was
doing, like finishing an internal operation (like <a href="../../lib/Pod/perlfunc.html#item_sort"><code>sort())</code></a> or an
external operation (like an I/O operation), and only then look at any
arrived signals (and before starting the next operation).  No more corrupt
internal state since the current operation is always finished first,
but the signal may take more time to get heard.  Note that breaking
out from potentially blocking operations should still work, though.</p>
<p>
</p>
<h2><a name="understanding_of_numbers">Understanding of Numbers</a></h2>
<p>In general a lot of fixing has happened in the area of Perl's
understanding of numbers, both integer and floating point.  Since in
many systems the standard number parsing functions like <code>strtoul()</code>
and <code>atof()</code> seem to have bugs, Perl tries to work around their
deficiencies.  This results hopefully in more accurate numbers.</p>
<p>Perl now tries internally to use integer values in numeric conversions
and basic arithmetics (+ - * /) if the arguments are integers, and
tries also to keep the results stored internally as integers.
This change leads to often slightly faster and always less lossy
arithmetics. (Previously Perl always preferred floating point numbers
in its math.)</p>
<p>
</p>
<h2><a name="arrays_now_always_interpolate_into_doublequoted_strings__561_">Arrays now always interpolate into double-quoted strings [561]</a></h2>
<p>In double-quoted strings, arrays now interpolate, no matter what.  The
behavior in earlier versions of perl 5 was that arrays would interpolate
into strings if the array had been mentioned before the string was
compiled, and otherwise Perl would raise a fatal compile-time error.
In versions 5.000 through 5.003, the error was</p>
<pre>
        Literal @example now requires backslash</pre>
<p>In versions 5.004_01 through 5.6.0, the error was</p>
<pre>
        In string, @example now must be written as \@example</pre>
<p>The idea here was to get people into the habit of writing
<code>&quot;fred\@example.com&quot;</code> when they wanted a literal <code>@</code> sign, just as
they have always written <code>&quot;Give me back my \$5&quot;</code> when they wanted a
literal <code>$</code> sign.</p>
<p>Starting with 5.6.1, when Perl now sees an <code>@</code> sign in a
double-quoted string, it <em>always</em> attempts to interpolate an array,
regardless of whether or not the array has been used or declared
already.  The fatal error has been downgraded to an optional warning:</p>
<pre>
        Possible unintended interpolation of @example in string</pre>
<p>This warns you that <code>&quot;fred@example.com&quot;</code> is going to turn into
<code>fred.com</code> if you don't backslash the <code>@</code>.
See <a href="http://www.plover.com/~mjd/perl/at-error.html">http://www.plover.com/~mjd/perl/at-error.html</a> for more details
about the history here.</p>
<p>
</p>
<h2><a name="miscellaneous_changes">Miscellaneous Changes</a></h2>
<ul>
<li>
<p>AUTOLOAD is now lvaluable, meaning that you can add the :lvalue attribute
to AUTOLOAD subroutines and you can assign to the AUTOLOAD return value.</p>
</li>
<li>
<p>The $Config{byteorder} (and corresponding BYTEORDER in config.h) was
previously wrong in platforms if <code>sizeof(long)</code> was 4, but <code>sizeof(IV)</code>
was 8.  The byteorder was only <code>sizeof(long)</code> bytes long (1234 or 4321),
but now it is correctly <code>sizeof(IV)</code> bytes long, (12345678 or 87654321).
(This problem didn't affect Windows platforms.)</p>
<p>Also, $Config{byteorder} is now computed dynamically--this is more
robust with &quot;fat binaries&quot; where an executable image contains binaries
for more than one binary platform, and when cross-compiling.</p>
</li>
<li>
<p><code>perl -d:Module=arg,arg,arg</code> now works (previously one couldn't pass
in multiple arguments.)</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_do"><code>do</code></a> followed by a bareword now ensures that this bareword isn't
a keyword (to avoid a bug where <code>do q(foo.pl)</code> tried to call a
subroutine called <code>q</code>).  This means that for example instead of
<a href="../../lib/Pod/perlfunc.html#item_format"><code>do format()</code></a> you must write <a href="../../lib/Pod/perlfunc.html#item_format"><code>do &amp;format()</code></a>.</p>
</li>
<li>
<p>The builtin <a href="../../lib/Pod/perlfunc.html#item_dump"><code>dump()</code></a> now gives an optional warning
<a href="../../lib/Pod/perlfunc.html#item_dump"><code>dump() better written as CORE::dump()</code></a>,
meaning that by default <a href="../../lib/Pod/perlfunc.html#item_dump"><code>dump(...)</code></a> is resolved as the builtin
<a href="../../lib/Pod/perlfunc.html#item_dump"><code>dump()</code></a> which dumps core and aborts, not as (possibly) user-defined
<code>sub dump</code>.  To call the latter, qualify the call as <a href="../../lib/Pod/perlfunc.html#item_dump"><code>&amp;dump(...)</code></a>.
(The whole <a href="../../lib/Pod/perlfunc.html#item_dump"><code>dump()</code></a> feature is to considered deprecated, and possibly
removed/changed in future releases.)</p>
</li>
<li>
<p><a href="../../lib/Pod/perlfunc.html#item_chomp"><code>chomp()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_chop"><code>chop()</code></a> are now overridable.  Note, however, that their
prototype (as given by <a href="../../lib/Pod/perlfunc.html#item_prototype"><code>prototype(&quot;CORE::chomp&quot;)</code></a> is undefined,
because it cannot be expressed and therefore one cannot really write
replacements to override these builtins.</p>
</li>
<li>
<p>END blocks are now run even if you exit/die in a BEGIN block.
Internally, the execution of END blocks is now controlled by
PL_exit_flags &amp; PERL_EXIT_DESTRUCT_END. This enables the new
behaviour for Perl embedders. This will default in 5.10. See
<a href="../../lib/Pod/perlembed.html">the perlembed manpage</a>.</p>
</li>
<li>
<p>Formats now support zero-padded decimal fields.</p>
</li>
<li>
<p>Although &quot;you shouldn't do that&quot;, it was possible to write code that
depends on Perl's hashed key order (Data::Dumper does this).  The new

⌨️ 快捷键说明

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