perl571delta.html

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

HTML
1,096 行
字号
</ul>
<p>
</p>
<h2><a name="signals_are_now_safe">Signals Are Now Safe</a></h2>
<p>Perl used to be fragile in that signals arriving at inopportune moments
could corrupt Perl's internal state.</p>
<p>
</p>
<hr />
<h1><a name="modules_and_pragmata">Modules and Pragmata</a></h1>
<p>
</p>
<h2><a name="new_modules">New Modules</a></h2>
<ul>
<li>
<p>B::Concise, by Stephen McCamant, is a new compiler backend for
walking the Perl syntax tree, printing concise info about ops.
The output is highly customisable.</p>
<p>See <a href="../../lib/B/Concise.html">the B::Concise manpage</a> for more information.</p>
</li>
<li>
<p>Class::ISA, by Sean Burke, for reporting the search path for a
class's ISA tree, has been added.</p>
<p>See <a href="../../lib/Class/ISA.html">the Class::ISA manpage</a> for more information.</p>
</li>
<li>
<p>Cwd has now a split personality: if possible, an extension is used,
(this will hopefully be both faster and more secure and robust) but
if not possible, the familiar Perl library implementation is used.</p>
</li>
<li>
<p>Digest, a frontend module for calculating digests (checksums),
from Gisle Aas, has been added.</p>
<p>See <a href="../../lib/Digest.html">the Digest manpage</a> for more information.</p>
</li>
<li>
<p>Digest::MD5 for calculating MD5 digests (checksums), by Gisle Aas,
has been added.</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 MD5 backward compatibility module is deliberately not
included since its use is discouraged.</p>
<p>See <a href="../../lib/Digest/MD5.html">the Digest::MD5 manpage</a> for more information.</p>
</li>
<li>
<p>Encode, by Nick Ing-Simmons, provides a mechanism to translate
between different character encodings.  Support for Unicode,
ISO-8859-*, ASCII, CP*, KOI8-R, and three variants of EBCDIC are
compiled in to the module.  Several other encodings (like Japanese,
Chinese, and MacIntosh encodings) are included and will be loaded at
runtime.</p>
<p>Any encoding supported by Encode module is also available to the
&quot;:encoding()&quot; layer if PerlIO is used.</p>
<p>See <a href="../../lib/Encode.html">the Encode manpage</a> for more information.</p>
</li>
<li>
<p>Filter::Simple is an easy-to-use frontend to Filter::Util::Call,
from Damian Conway.</p>
<pre>
    <span class="comment"># in MyFilter.pm:</span>
</pre>
<pre>
    <span class="keyword">package</span> <span class="variable">MyFilter</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">use</span> <span class="variable">Filter::Simple</span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span>
        <span class="keyword">while</span> <span class="operator">(</span><span class="keyword">my</span> <span class="operator">(</span><span class="variable">$from</span><span class="operator">,</span> <span class="variable">$to</span><span class="operator">)</span> <span class="operator">=</span> <span class="keyword">splice</span> <span class="variable">@_</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">2</span><span class="operator">)</span> <span class="operator">{</span>
                <span class="regex">s/$from/$to/g</span><span class="operator">;</span>
        <span class="operator">}</span>
    <span class="operator">};</span>
</pre>
<pre>
    <span class="number">1</span><span class="operator">;</span>
</pre>
<pre>
    <span class="comment"># in user's code:</span>
</pre>
<pre>
    <span class="keyword">use</span> <span class="variable">MyFilter</span> <span class="string">qr/red/</span> <span class="operator">=&gt;</span> <span class="string">'green'</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">print</span> <span class="string">"red\n"</span><span class="operator">;</span>   <span class="comment"># this code is filtered, will print "green\n"</span>
    <span class="keyword">print</span> <span class="string">"bored\n"</span><span class="operator">;</span> <span class="comment"># this code is filtered, will print "bogreen\n"</span>
</pre>
<pre>
    <span class="keyword">no</span> <span class="variable">MyFilter</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">print</span> <span class="string">"red\n"</span><span class="operator">;</span>   <span class="comment"># this code is not filtered, will print "red\n"</span>
</pre>
<p>See <a href="../../lib/Filter/Simple.html">the Filter::Simple manpage</a> for more information.</p>
</li>
<li>
<p>Filter::Util::Call, by Paul Marquess, provides you with the
framework to write <em>Source Filters</em> in Perl.  For most uses
the frontend Filter::Simple is to be preferred.
See <a href="../../lib/Filter/Util/Call.html">the Filter::Util::Call manpage</a> for more information.</p>
</li>
<li>
<p>Locale::Constants, Locale::Country, Locale::Currency, and Locale::Language,
from Neil Bowers, have been added.  They provide the codes for various
locale standards, such as &quot;fr&quot; for France, &quot;usd&quot; for US Dollar, and
&quot;jp&quot; for Japanese.</p>
<pre>
    <span class="keyword">use</span> <span class="variable">Locale::Country</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">$country</span> <span class="operator">=</span> <span class="variable">code2country</span><span class="operator">(</span><span class="string">'jp'</span><span class="operator">);</span>               <span class="comment"># $country gets 'Japan'</span>
    <span class="variable">$code</span>    <span class="operator">=</span> <span class="variable">country2code</span><span class="operator">(</span><span class="string">'Norway'</span><span class="operator">);</span>           <span class="comment"># $code gets 'no'</span>
</pre>
<p>See <a href="../../lib/Locale/Constants.html">the Locale::Constants manpage</a>, <a href="../../lib/Locale/Country.html">the Locale::Country manpage</a>, <a href="../../lib/Locale/Currency.html">the Locale::Currency manpage</a>,
and <a href="../../lib/Locale/Language.html">the Locale::Language manpage</a> for more information.</p>
</li>
<li>
<p>MIME::Base64, by Gisle Aas, allows you to encode data in base64.</p>
<pre>
    <span class="keyword">use</span> <span class="variable">MIME::Base64</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">$encoded</span> <span class="operator">=</span> <span class="variable">encode_base64</span><span class="operator">(</span><span class="string">'Aladdin:open sesame'</span><span class="operator">);</span>
    <span class="variable">$decoded</span> <span class="operator">=</span> <span class="variable">decode_base64</span><span class="operator">(</span><span class="variable">$encoded</span><span class="operator">);</span>
</pre>
<pre>
    <span class="keyword">print</span> <span class="variable">$encoded</span><span class="operator">,</span> <span class="string">"\n"</span><span class="operator">;</span> <span class="comment"># "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="</span>
</pre>
<p>See <a href="../../lib/MIME/Base64.html">the MIME::Base64 manpage</a> for more information.</p>
</li>
<li>
<p>MIME::QuotedPrint, by Gisle Aas, allows you to encode data in
quoted-printable encoding.</p>
<pre>
    <span class="keyword">use</span> <span class="variable">MIME::QuotedPrint</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">$encoded</span> <span class="operator">=</span> <span class="variable">encode_qp</span><span class="operator">(</span><span class="string">"Smiley in Unicode: \x{263a}"</span><span class="operator">);</span>
    <span class="variable">$decoded</span> <span class="operator">=</span> <span class="variable">decode_qp</span><span class="operator">(</span><span class="variable">$encoded</span><span class="operator">);</span>
</pre>
<pre>
    <span class="keyword">print</span> <span class="variable">$encoded</span><span class="operator">,</span> <span class="string">"\n"</span><span class="operator">;</span> <span class="comment"># "Smiley in Unicode: =263A"</span>
</pre>
<p>MIME::QuotedPrint has been enhanced to provide the basic methods
necessary to use it with PerlIO::Via as in :</p>
<pre>
    <span class="keyword">use</span> <span class="variable">MIME::QuotedPrint</span><span class="operator">;</span>
    <span class="keyword">open</span><span class="operator">(</span><span class="variable">$fh</span><span class="operator">,</span><span class="string">"&gt;Via(MIME::QuotedPrint)"</span><span class="operator">,</span><span class="variable">$path</span><span class="operator">)</span>
</pre>
<p>See <a href="../../lib/MIME/QuotedPrint.html">the MIME::QuotedPrint manpage</a> for more information.</p>
</li>
<li>
<p>PerlIO::Scalar, by Nick Ing-Simmons, provides the implementation of
IO to &quot;in memory&quot; Perl scalars as discussed above.  It also serves as
an example of a loadable layer.  Other future possibilities include
PerlIO::Array and PerlIO::Code.  See <a href="../../PerlIO/Scalar.html">the PerlIO::Scalar manpage</a> for more
information.</p>
</li>
<li>
<p>PerlIO::Via, by Nick Ing-Simmons, acts as a PerlIO layer and wraps
PerlIO layer functionality provided by a class (typically implemented
in perl code).</p>
<pre>
    <span class="keyword">use</span> <span class="variable">MIME::QuotedPrint</span><span class="operator">;</span>
    <span class="keyword">open</span><span class="operator">(</span><span class="variable">$fh</span><span class="operator">,</span><span class="string">"&gt;Via(MIME::QuotedPrint)"</span><span class="operator">,</span><span class="variable">$path</span><span class="operator">)</span>
</pre>
<p>This will automatically convert everything output to <code>$fh</code>
to Quoted-Printable.  See <a href="../../PerlIO/Via.html">the PerlIO::Via manpage</a> for more information.</p>
</li>
<li>
<p>Pod::Text::Overstrike, by Joe Smith, has been added.
It converts POD data to formatted overstrike text.
See <a href="../../lib/Pod/Text/Overstrike.html">the Pod::Text::Overstrike manpage</a> for more information.</p>
</li>
<li>
<p>Switch from Damian Conway has been added.  Just by saying</p>
<pre>
    <span class="keyword">use</span> <span class="variable">Switch</span><span class="operator">;</span>
</pre>
<p>you have <code>switch</code> and <code>case</code> available in Perl.</p>
<pre>
    <span class="keyword">use</span> <span class="variable">Switch</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">switch</span> <span class="operator">(</span><span class="variable">$val</span><span class="operator">)</span> <span class="operator">{</span>
</pre>
<pre>
                <span class="variable">case</span> <span class="number">1</span>          <span class="operator">{</span> <span class="keyword">print</span> <span class="string">"number 1"</span> <span class="operator">}</span>
                <span class="variable">case</span> <span class="string">"a"</span>        <span class="operator">{</span> <span class="keyword">print</span> <span class="string">"string a"</span> <span class="operator">}</span>
                <span class="variable">case</span> <span class="operator">[</span><span class="number">1</span><span class="operator">..</span><span class="number">10</span><span class="operator">,</span><span class="number">42</span><span class="operator">]</span> <span class="operator">{</span> <span class="keyword">print</span> <span class="string">"number in list"</span> <span class="operator">}</span>
                <span class="variable">case</span> <span class="operator">(</span><span class="variable">@array</span><span class="operator">)</span>   <span class="operator">{</span> <span class="keyword">print</span> <span class="string">"number in list"</span> <span class="operator">}</span>
                <span class="variable">case</span> <span class="operator">/\</span><span class="variable">w</span><span class="operator">+</span><span class="regex">/      { print "pattern" }
                case qr/</span><span class="operator">\</span><span class="variable">w</span><span class="operator">+</span><span class="regex">/    { print "pattern" }
                case (%hash)    { print "entry in hash" }
                case (\%hash)   { print "entry in hash" }
                case (\&amp;sub)    { print "arg to subroutine" }
                else            { print "previous case not true" }
                    }
                </span>
</pre>
<p>See <a href="../../lib/Switch.html">the Switch manpage</a> for more information.</p>
</li>
<li>
<p>Text::Balanced from Damian Conway has been added, for
extracting delimited text sequences from strings.</p>
<pre>
    <span class="keyword">use</span> <span class="variable">Text::Balanced</span> <span class="string">'extract_delimited'</span><span class="operator">;</span>
</pre>
<pre>
    <span class="operator">(</span><span class="variable">$a</span><span class="operator">,</span> <span class="variable">$b</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">extract_delimited</span><span class="operator">(</span><span class="string">"'never say never', he never said"</span><span class="operator">,</span> <span class="string">"'"</span><span class="operator">,</span> <span class="string">''</span><span class="operator">);</span>
</pre>
<p>$a will be &quot;'never say never'&quot;, $b will be ', he never said'.</p>
<p>In addition to <code>extract_delimited()</code> there are also extract_bracketed(),
extract_quotelike(), extract_codeblock(), extract_variable(),
extract_tagged(), extract_multiple(), gen_delimited_pat(), and
gen_extract_tagged().  With these you can implement rather advanced
parsing algorithms.  See <a href="../../lib/Text/Balanced.html">the Text::Balanced manpage</a> for more information.</p>
</li>
<li>
<p>Tie::RefHash::Nestable, by Edward Avis, allows storing hash references
(unlike the standard Tie::RefHash)  The module is contained within
Tie::RefHash.</p>
</li>
<li>
<p>XS::Typemap, by Tim Jenness, is a test extension that exercises XS
typemaps.  Nothing gets installed but for extension writers the code
is worth studying.</p>
</li>
</ul>
<p>
</p>
<h2><a name="updated_and_improved_modules_and_pragmata">Updated And Improved Modules and Pragmata</a></h2>
<ul>
<li>
<p>B::Deparse should be now more robust.  It still far from providing a full
round trip for any random piece of Perl code, though, and is under active
development: expect more robustness in 5.7.2.</p>
</li>
<li>
<p>Class::Struct can now define the classes in compile time.</p>
</li>
<li>
<p>Math::BigFloat has undergone much fixing, and in addition the <code>fmod()</code>
function now supports modulus operations.</p>
<p>( The fixed Math::BigFloat module is also available in CPAN for those
who can't upgrade their Perl: <a href="http://www.cpan.org/authors/id/J/JP/JPEACOCK/">http://www.cpan.org/authors/id/J/JP/JPEACOCK/</a> )</p>
</li>
<li>
<p>Devel::Peek now has an interface for the Perl memory statistics
(this works only if you are using perl's malloc, and if you have
compiled with debugging).</p>
</li>
<li>
<p>IO::Socket has now <code>atmark()</code> method, which returns true if the socket
is positioned at the out-of-band mark.  The method is also exportable
as a <code>sockatmark()</code> function.</p>
</li>
<li>
<p>IO::Socket::INET has support for ReusePort option (if your platform
supports it).  The Reuse option now has an alias, ReuseAddr.  For clarity
you may want to prefer ReuseAddr.</p>
</li>
<li>
<p>Net::Ping has been enhanced.  There is now &quot;external&quot; protocol which
uses Net::Ping::External module which runs external <code>ping(1)</code> and parses
the output.  An alpha version of Net::Ping::External is available in
CPAN and in 5.7.2 the Net::Ping::External may be integrated to Perl.</p>
</li>
<li>
<p>The <a href="../../lib/Pod/perlfunc.html#item_open"><code>open</code></a> pragma allows layers other than &quot;:raw&quot; and &quot;:crlf&quot; when

⌨️ 快捷键说明

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