📄 perl5004delta.1
字号:
.el .IP "\f(CW$_\fR as Default" 4.IX Item "$_ as Default"Functions documented in the Camel to default to \f(CW$_\fR now infact do, and all those that do are so documented in perlfunc..ie n .IP """m//gc"" does not reset search position on failure" 4.el .IP "\f(CWm//gc\fR does not reset search position on failure" 4.IX Item "m//gc does not reset search position on failure"The \f(CW\*(C`m//g\*(C'\fR match iteration construct has always reset its targetstring's search position (which is visible through the \f(CW\*(C`pos\*(C'\fR operator)when a match fails; as a result, the next \f(CW\*(C`m//g\*(C'\fR match after a failurestarts again at the beginning of the string. With Perl 5.004, thisreset may be disabled by adding the \*(L"c\*(R" (for \*(L"continue\*(R") modifier,i.e. \f(CW\*(C`m//gc\*(C'\fR. This feature, in conjunction with the \f(CW\*(C`\eG\*(C'\fR zero-widthassertion, makes it possible to chain matches together. See perlopand perlre..ie n .IP """m//x"" ignores whitespace before ?*+{}" 4.el .IP "\f(CWm//x\fR ignores whitespace before ?*+{}" 4.IX Item "m//x ignores whitespace before ?*+{}"The \f(CW\*(C`m//x\*(C'\fR construct has always been intended to ignore all unescapedwhitespace. However, before Perl 5.004, whitespace had the effect ofescaping repeat modifiers like \*(L"*\*(R" or \*(L"?\*(R"; for example, \f(CW\*(C`/a *b/x\*(C'\fR was(mis)interpreted as \f(CW\*(C`/a\e*b/x\*(C'\fR. This bug has been fixed in 5.004..ie n .IP "nested ""sub{}"" closures work now" 4.el .IP "nested \f(CWsub{}\fR closures work now" 4.IX Item "nested sub{} closures work now"Prior to the 5.004 release, nested anonymous functions didn't workright. They do now..IP "formats work right on changing lexicals" 4.IX Item "formats work right on changing lexicals"Just like anonymous functions that contain lexical variablesthat change (like a lexical index variable for a \f(CW\*(C`foreach\*(C'\fR loop),formats now work properly. For example, this silently failedbefore (printed only zeros), but is fine now:.Sp.Vb 8\& my $i;\& foreach $i ( 1 .. 10 ) {\& write;\& }\& format =\& my i is @#\& $i\& ..Ve.SpHowever, it still fails (without a warning) if the foreach is within asubroutine:.Sp.Vb 11\& my $i;\& sub foo {\& foreach $i ( 1 .. 10 ) {\& write;\& }\& }\& foo;\& format =\& my i is @#\& $i\& ..Ve.Sh "New builtin methods".IX Subsection "New builtin methods"The \f(CW\*(C`UNIVERSAL\*(C'\fR package automatically contains the following methods thatare inherited by all other classes:.IP "isa(\s-1CLASS\s0)" 4.IX Item "isa(CLASS)"\&\f(CW\*(C`isa\*(C'\fR returns \fItrue\fR if its object is blessed into a subclass of \f(CW\*(C`CLASS\*(C'\fR.Sp\&\f(CW\*(C`isa\*(C'\fR is also exportable and can be called as a sub with two arguments. Thisallows the ability to check what a reference points to. Example:.Sp.Vb 1\& use UNIVERSAL qw(isa);\&\& if(isa($ref, \*(AqARRAY\*(Aq)) {\& ...\& }.Ve.IP "can(\s-1METHOD\s0)" 4.IX Item "can(METHOD)"\&\f(CW\*(C`can\*(C'\fR checks to see if its object has a method called \f(CW\*(C`METHOD\*(C'\fR,if it does then a reference to the sub is returned; if it does not then\&\fIundef\fR is returned..IP "\s-1VERSION\s0( [\s-1NEED\s0] )" 4.IX Item "VERSION( [NEED] )"\&\f(CW\*(C`VERSION\*(C'\fR returns the version number of the class (package). If the\&\s-1NEED\s0 argument is given then it will check that the current version (asdefined by the \f(CW$VERSION\fR variable in the given package) not less than\&\s-1NEED\s0; it will die if this is not the case. This method is normallycalled as a class method. This method is called automatically by the\&\f(CW\*(C`VERSION\*(C'\fR form of \f(CW\*(C`use\*(C'\fR..Sp.Vb 3\& use A 1.2 qw(some imported subs);\& # implies:\& A\->VERSION(1.2);.Ve.PP\&\fB\s-1NOTE:\s0\fR \f(CW\*(C`can\*(C'\fR directly uses Perl's internal code for method lookup, and\&\f(CW\*(C`isa\*(C'\fR uses a very similar method and caching strategy. This may causestrange effects if the Perl code dynamically changes \f(CW@ISA\fR in any package..PPYou may add other methods to the \s-1UNIVERSAL\s0 class via Perl or \s-1XS\s0 code.You do not need to \f(CW\*(C`use UNIVERSAL\*(C'\fR in order to make these methodsavailable to your program. This is necessary only if you wish tohave \f(CW\*(C`isa\*(C'\fR available as a plain subroutine in the current package..Sh "\s-1TIEHANDLE\s0 now supported".IX Subsection "TIEHANDLE now supported"See perltie for other kinds of \fItie()\fRs..IP "\s-1TIEHANDLE\s0 classname, \s-1LIST\s0" 4.IX Item "TIEHANDLE classname, LIST"This is the constructor for the class. That means it is expected toreturn an object of some sort. The reference can be used tohold some internal information..Sp.Vb 5\& sub TIEHANDLE {\& print "<shout>\en";\& my $i;\& return bless \e$i, shift;\& }.Ve.IP "\s-1PRINT\s0 this, \s-1LIST\s0" 4.IX Item "PRINT this, LIST"This method will be triggered every time the tied handle is printed to.Beyond its self reference it also expects the list that was passed tothe print function..Sp.Vb 5\& sub PRINT {\& $r = shift;\& $$r++;\& return print join( $, => map {uc} @_), $\e;\& }.Ve.IP "\s-1PRINTF\s0 this, \s-1LIST\s0" 4.IX Item "PRINTF this, LIST"This method will be triggered every time the tied handle is printed towith the \f(CW\*(C`printf()\*(C'\fR function.Beyond its self reference it also expects the format and list that waspassed to the printf function..Sp.Vb 5\& sub PRINTF {\& shift;\& my $fmt = shift;\& print sprintf($fmt, @_)."\en";\& }.Ve.IP "\s-1READ\s0 this \s-1LIST\s0" 4.IX Item "READ this LIST"This method will be called when the handle is read from via the \f(CW\*(C`read\*(C'\fRor \f(CW\*(C`sysread\*(C'\fR functions..Sp.Vb 5\& sub READ {\& $r = shift;\& my($buf,$len,$offset) = @_;\& print "READ called, \e$buf=$buf, \e$len=$len, \e$offset=$offset";\& }.Ve.IP "\s-1READLINE\s0 this" 4.IX Item "READLINE this"This method will be called when the handle is read from. The methodshould return undef when there is no more data..Sp.Vb 4\& sub READLINE {\& $r = shift;\& return "PRINT called $$r times\en"\& }.Ve.IP "\s-1GETC\s0 this" 4.IX Item "GETC this"This method will be called when the \f(CW\*(C`getc\*(C'\fR function is called..Sp.Vb 1\& sub GETC { print "Don\*(Aqt GETC, Get Perl"; return "a"; }.Ve.IP "\s-1DESTROY\s0 this" 4.IX Item "DESTROY this"As with the other types of ties, this method will be called when thetied handle is about to be destroyed. This is useful for debugging andpossibly for cleaning up..Sp.Vb 3\& sub DESTROY {\& print "</shout>\en";\& }.Ve.Sh "Malloc enhancements".IX Subsection "Malloc enhancements"If perl is compiled with the malloc included with the perl distribution(that is, if \f(CW\*(C`perl \-V:d_mymalloc\*(C'\fR is 'define') then you can printmemory statistics at runtime by running Perl thusly:.PP.Vb 1\& env PERL_DEBUG_MSTATS=2 perl your_script_here.Ve.PPThe value of 2 means to print statistics after compilation and onexit; with a value of 1, the statistics are printed only on exit.(If you want the statistics at an arbitrary time, you'll need toinstall the optional module Devel::Peek.).PPThree new compilation flags are recognized by malloc.c. (They have noeffect if perl is compiled with system \fImalloc()\fR.).IP "\-DPERL_EMERGENCY_SBRK" 4.IX Item "-DPERL_EMERGENCY_SBRK"If this macro is defined, running out of memory need not be a fatalerror: a memory pool can allocated by assigning to the specialvariable \f(CW$^M\fR. See \*(L"$^M\*(R"..IP "\-DPACK_MALLOC" 4.IX Item "-DPACK_MALLOC"Perl memory allocation is by bucket with sizes close to powers of two.Because of these malloc overhead may be big, especially for data ofsize exactly a power of two. If \f(CW\*(C`PACK_MALLOC\*(C'\fR is defined, perl usesa slightly different algorithm for small allocations (up to 64 byteslong), which makes it possible to have overhead down to 1 byte forallocations which are powers of two (and appear quite often)..SpExpected memory savings (with 8\-byte alignment in \f(CW\*(C`alignbytes\*(C'\fR) isabout 20% for typical Perl usage. Expected slowdown due to additionalmalloc overhead is in fractions of a percent (hard to measure, becauseof the effect of saved memory on speed)..IP "\-DTWO_POT_OPTIMIZE" 4.IX Item "-DTWO_POT_OPTIMIZE"Similarly to \f(CW\*(C`PACK_MALLOC\*(C'\fR, this macro improves allocations of datawith size close to a power of two; but this works for big allocations(starting with 16K by default). Such allocations are typical for bighashes and special-purpose scripts, especially image processing..SpOn recent systems, the fact that perl requires 2M from system for 1Mallocation will not affect speed of execution, since the tail of sucha chunk is not going to be touched (and thus will not require realmemory). However, it may result in a premature out-of-memory error.So if you will be manipulating very large blocks with sizes close topowers of two, it would be wise to define this macro..SpExpected saving of memory is 0\-100% (100% in applications whichrequire most memory in such 2**n chunks); expected slowdown isnegligible..Sh "Miscellaneous efficiency enhancements".IX Subsection "Miscellaneous efficiency enhancements"Functions that have an empty prototype and that do nothing but returna fixed value are now inlined (e.g. \f(CW\*(C`sub PI () { 3.14159 }\*(C'\fR)..PPEach unique hash key is only allocated once, no matter how many hasheshave an entry with that key. So even if you have 100 copies of thesame hash, the hash keys never have to be reallocated..SH "Support for More Operating Systems".IX Header "Support for More Operating Systems"Support for the following operating systems is new in Perl 5.004..Sh "Win32".IX Subsection "Win32"Perl 5.004 now includes support for building a \*(L"native\*(R" perl underWindows \s-1NT\s0, using the Microsoft Visual \*(C+ compiler (versions 2.0and above) or the Borland \*(C+ compiler (versions 5.02 and above).The resulting perl can be used under Windows 95 (if itis installed in the same directory locations as it got installedin Windows \s-1NT\s0). This port includes support for perl extensionbuilding tools like MakeMaker and h2xs, so that many extensionsavailable on the Comprehensive Perl Archive Network (\s-1CPAN\s0) can now bereadily built under Windows \s-1NT\s0. See http://www.perl.com/ for moreinformation on \s-1CPAN\s0 and \fI\s-1README\s0.win32\fR in the perl distribution for moredetails on how to get started with building this port..PPThere is also support for building perl under the Cygwin32 environment.Cygwin32 is a set of \s-1GNU\s0 tools that make it possible to compile and runmany Unix programs under Windows \s-1NT\s0 by providing a mostly Unix-like interface for compilation and execution. See \fI\s-1README\s0.cygwin32\fR in theperl distribution for more details on this port and how to obtain theCygwin32 toolkit..Sh "Plan 9".IX Subsection "Plan 9"See \fI\s-1README\s0.plan9\fR in the perl distribution..Sh "\s-1QNX\s0".IX Subsection "QNX"See \fI\s-1README\s0.qnx\fR in the perl distribution..Sh "AmigaOS".IX Subsection "AmigaOS"See \fI\s-1README\s0.amigaos\fR in the perl distribution..SH "Pragmata".IX Header "Pragmata"Six new pragmatic modules exist:.IP "use autouse \s-1MODULE\s0 => qw(sub1 sub2 sub3)" 4.IX Item "use autouse MODULE => qw(sub1 sub2 sub3)"Defers \f(CW\*(C`require MODULE\*(C'\fR until someone calls one of the specifiedsubroutines (which must be exported by \s-1MODULE\s0). This pragma should beused with caution, and only when necessary..IP "use blib" 4.IX Item "use blib".PD 0.IP "use blib 'dir'" 4.IX Item "use blib 'dir'"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -