perl5100delta.pod

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 1,592 行 · 第 1/4 页

POD
1,592
字号
=encoding utf8=head1 NAMEperldelta - what is new for perl 5.10.0=head1 DESCRIPTIONThis document describes the differences between the 5.8.8 release andthe 5.10.0 release.Many of the bug fixes in 5.10.0 were already seen in the 5.8.X maintenancereleases; they are not duplicated here and are documented in the set ofman pages named perl58[1-8]?delta.=head1 Core Enhancements=head2 The C<feature> pragmaThe C<feature> pragma is used to enable new syntax that would break Perl'sbackwards-compatibility with older releases of the language. It's a lexicalpragma, like C<strict> or C<warnings>.Currently the following new features are available: C<switch> (adds aswitch statement), C<say> (adds a C<say> built-in function), and C<state>(adds a C<state> keyword for declaring "static" variables). Thosefeatures are described in their own sections of this document.The C<feature> pragma is also implicitly loaded when you require a minimalperl version (with the C<use VERSION> construct) greater than, or equalto, 5.9.5. See L<feature> for details.=head2 New B<-E> command-line switchB<-E> is equivalent to B<-e>, but it implicitly enables alloptional features (like C<use feature ":5.10">).=head2 Defined-or operatorA new operator C<//> (defined-or) has been implemented.The following expression:    $a // $bis merely equivalent to   defined $a ? $a : $band the statement   $c //= $d;can now be used instead of   $c = $d unless defined $c;The C<//> operator has the same precedence and associativity as C<||>.Special care has been taken to ensure that this operator Do What You Meanwhile not breaking old code, but some edge cases involving the emptyregular expression may now parse differently.  See L<perlop> fordetails.=head2 Switch and Smart Match operatorPerl 5 now has a switch statement. It's available when C<use feature'switch'> is in effect. This feature introduces three new keywords,C<given>, C<when>, and C<default>:    given ($foo) {	when (/^abc/) { $abc = 1; }	when (/^def/) { $def = 1; }	when (/^xyz/) { $xyz = 1; }	default { $nothing = 1; }    }A more complete description of how Perl matches the switch variableagainst the C<when> conditions is given in L<perlsyn/"Switch statements">.This kind of match is called I<smart match>, and it's also possible to useit outside of switch statements, via the new C<~~> operator. SeeL<perlsyn/"Smart matching in detail">.This feature was contributed by Robin Houston.=head2 Regular expressions=over 4=item Recursive PatternsIt is now possible to write recursive patterns without using the C<(??{})>construct. This new way is more efficient, and in many cases easier toread.Each capturing parenthesis can now be treated as an independent patternthat can be entered by using the C<(?PARNO)> syntax (C<PARNO> standing for"parenthesis number"). For example, the following pattern will matchnested balanced angle brackets:    /     ^                      # start of line     (                      # start capture buffer 1	<                   #   match an opening angle bracket	(?:                 #   match one of:	    (?>             #     don't backtrack over the inside of this group		[^<>]+      #       one or more non angle brackets	    )               #     end non backtracking group	|                   #     ... or ...	    (?1)            #     recurse to bracket 1 and try it again	)*                  #   0 or more times.	>                   #   match a closing angle bracket     )                      # end capture buffer one     $                      # end of line    /xPCRE users should note that Perl's recursive regex feature allowsbacktracking into a recursed pattern, whereas in PCRE the recursion isatomic or "possessive" in nature.  As in the example above, you canadd (?>) to control this selectively.  (Yves Orton)=item Named Capture BuffersIt is now possible to name capturing parenthesis in a pattern and refer tothe captured contents by name. The naming syntax is C<< (?<NAME>....) >>.It's possible to backreference to a named buffer with the C<< \k<NAME> >>syntax. In code, the new magical hashes C<%+> and C<%-> can be used toaccess the contents of the capture buffers.Thus, to replace all doubled chars with a single copy, one could write    s/(?<letter>.)\k<letter>/$+{letter}/gOnly buffers with defined contents will be "visible" in the C<%+> hash, soit's possible to do something like    foreach my $name (keys %+) {        print "content of buffer '$name' is $+{$name}\n";    }The C<%-> hash is a bit more complete, since it will contain array refsholding values from all capture buffers similarly named, if there shouldbe many of them.C<%+> and C<%-> are implemented as tied hashes through the new moduleC<Tie::Hash::NamedCapture>.Users exposed to the .NET regex engine will find that the perlimplementation differs in that the numerical ordering of the buffersis sequential, and not "unnamed first, then named". Thus in the pattern   /(A)(?<B>B)(C)(?<D>D)/$1 will be 'A', $2 will be 'B', $3 will be 'C' and $4 will be 'D' and not$1 is 'A', $2 is 'C' and $3 is 'B' and $4 is 'D' that a .NET programmerwould expect. This is considered a feature. :-) (Yves Orton)=item Possessive QuantifiersPerl now supports the "possessive quantifier" syntax of the "atomic match"pattern. Basically a possessive quantifier matches as much as it can and nevergives any back. Thus it can be used to control backtracking. The syntax issimilar to non-greedy matching, except instead of using a '?' as the modifierthe '+' is used. Thus C<?+>, C<*+>, C<++>, C<{min,max}+> are now legalquantifiers. (Yves Orton)=item Backtracking control verbsThe regex engine now supports a number of special-purpose backtrackcontrol verbs: (*THEN), (*PRUNE), (*MARK), (*SKIP), (*COMMIT), (*FAIL)and (*ACCEPT). See L<perlre> for their descriptions. (Yves Orton)=item Relative backreferencesA new syntax C<\g{N}> or C<\gN> where "N" is a decimal integer allows asafer form of back-reference notation as well as allowing relativebackreferences. This should make it easier to generate and embed patternsthat contain backreferences. See L<perlre/"Capture buffers">. (Yves Orton)=item C<\K> escapeThe functionality of Jeff Pinyan's module Regexp::Keep has been added tothe core. In regular expressions you can now use the special escape C<\K>as a way to do something like floating length positive lookbehind. It isalso useful in substitutions like:  s/(foo)bar/$1/gthat can now be converted to  s/foo\Kbar//gwhich is much more efficient. (Yves Orton)=item Vertical and horizontal whitespace, and linebreakRegular expressions now recognize the C<\v> and C<\h> escapes that matchvertical and horizontal whitespace, respectively. C<\V> and C<\H>logically match their complements.C<\R> matches a generic linebreak, that is, vertical whitespace, plusthe multi-character sequence C<"\x0D\x0A">.=back=head2 C<say()>say() is a new built-in, only available when C<use feature 'say'> is ineffect, that is similar to print(), but that implicitly appends a newlineto the printed string. See L<perlfunc/say>. (Robin Houston)=head2 Lexical C<$_>The default variable C<$_> can now be lexicalized, by declaring it likeany other lexical variable, with a simple    my $_;The operations that default on C<$_> will use the lexically-scopedversion of C<$_> when it exists, instead of the global C<$_>.In a C<map> or a C<grep> block, if C<$_> was previously my'ed, then theC<$_> inside the block is lexical as well (and scoped to the block).In a scope where C<$_> has been lexicalized, you can still have access tothe global version of C<$_> by using C<$::_>, or, more simply, byoverriding the lexical declaration with C<our $_>. (Rafael Garcia-Suarez)=head2 The C<_> prototypeA new prototype character has been added. C<_> is equivalent to C<$> butdefaults to C<$_> if the corresponding argument isn't supplied. (both C<$>and C<_> denote a scalar). Due to the optional nature of the argument, youcan only use it at the end of a prototype, or before a semicolon.This has a small incompatible consequence: the prototype() function hasbeen adjusted to return C<_> for some built-ins in appropriate cases (forexample, C<prototype('CORE::rmdir')>). (Rafael Garcia-Suarez)=head2 UNITCHECK blocksC<UNITCHECK>, a new special code block has been introduced, in addition toC<BEGIN>, C<CHECK>, C<INIT> and C<END>.C<CHECK> and C<INIT> blocks, while useful for some specialized purposes,are always executed at the transition between the compilation and theexecution of the main program, and thus are useless whenever code isloaded at runtime. On the other hand, C<UNITCHECK> blocks are executedjust after the unit which defined them has been compiled. See L<perlmod>for more information. (Alex Gough)=head2 New Pragma, C<mro>A new pragma, C<mro> (for Method Resolution Order) has been added. Itpermits to switch, on a per-class basis, the algorithm that perl uses tofind inherited methods in case of a multiple inheritance hierarchy. Thedefault MRO hasn't changed (DFS, for Depth First Search). Another MRO isavailable: the C3 algorithm. See L<mro> for more information.(Brandon Black)Note that, due to changes in the implementation of class hierarchy search,code that used to undef the C<*ISA> glob will most probably break. Anyway,undef'ing C<*ISA> had the side-effect of removing the magic on the @ISAarray and should not have been done in the first place. Also, thecache C<*::ISA::CACHE::> no longer exists; to force reset the @ISA cache,you now need to use the C<mro> API, or more simply to assign to @ISA(e.g. with C<@ISA = @ISA>).=head2 readdir() may return a "short filename" on WindowsThe readdir() function may return a "short filename" when the longfilename contains characters outside the ANSI codepage.  SimilarlyCwd::cwd() may return a short directory name, and glob() may return shortnames as well.  On the NTFS file system these short names can always berepresented in the ANSI codepage.  This will not be true for all other filesystem drivers; e.g. the FAT filesystem stores short filenames in the OEMcodepage, so some files on FAT volumes remain unaccessible through theANSI APIs.Similarly, $^X, @INC, and $ENV{PATH} are preprocessed at startup to makesure all paths are valid in the ANSI codepage (if possible).The Win32::GetLongPathName() function now returns the UTF-8 encodedcorrect long file name instead of using replacement characters to forcethe name into the ANSI codepage.  The new Win32::GetANSIPathName()function can be used to turn a long pathname into a short one only if thelong one cannot be represented in the ANSI codepage.Many other functions in the C<Win32> module have been improved to acceptUTF-8 encoded arguments.  Please see L<Win32> for details.=head2 readpipe() is now overridableThe built-in function readpipe() is now overridable. Overriding it permitsalso to override its operator counterpart, C<qx//> (a.k.a. C<``>).Moreover, it now defaults to C<$_> if no argument is provided. (RafaelGarcia-Suarez)=head2 Default argument for readline()readline() now defaults to C<*ARGV> if no argument is provided. (RafaelGarcia-Suarez)=head2 state() variablesA new class of variables has been introduced. State variables are similarto C<my> variables, but are declared with the C<state> keyword in place ofC<my>. They're visible only in their lexical scope, but their value ispersistent: unlike C<my> variables, they're not undefined at scope entry,but retain their previous value. (Rafael Garcia-Suarez, Nicholas Clark)To use state variables, one needs to enable them by using    use feature 'state';or by using the C<-E> command-line switch in one-liners.See L<perlsub/"Persistent variables via state()">.=head2 Stacked filetest operatorsAs a new form of syntactic sugar, it's now possible to stack up filetestoperators. You can now write C<-f -w -x $file> in a row to meanC<-x $file && -w _ && -f _>. See L<perlfunc/-X>.=head2 UNIVERSAL::DOES()The C<UNIVERSAL> class has a new method, C<DOES()>. It has been added tosolve semantic problems with the C<isa()> method. C<isa()> checks forinheritance, while C<DOES()> has been designed to be overridden whenmodule authors use other types of relations between classes (in additionto inheritance). (chromatic)See L<< UNIVERSAL/"$obj->DOES( ROLE )" >>.=head2 FormatsFormats were improved in several ways. A new field, C<^*>, can be used forvariable-width, one-line-at-a-time text. Null characters are now handledcorrectly in picture lines. Using C<@#> and C<~~> together will nowproduce a compile-time error, as those format fields are incompatible.L<perlform> has been improved, and miscellaneous bugs fixed.=head2 Byte-order modifiers for pack() and unpack()There are two new byte-order modifiers, C<E<gt>> (big-endian) and C<E<lt>>(little-endian), that can be appended to most pack() and unpack() templatecharacters and groups to force a certain byte-order for that type or group.See L<perlfunc/pack> and L<perlpacktut> for details.=head2 C<no VERSION>You can now use C<no> followed by a version number to specify that youwant to use a version of perl older than the specified one.=head2 C<chdir>, C<chmod> and C<chown> on filehandlesC<chdir>, C<chmod> and C<chown> can now work on filehandles as well asfilenames, if the system supports respectively C<fchdir>, C<fchmod> andC<fchown>, thanks to a patch provided by Gisle Aas.=head2 OS groupsC<$(> and C<$)> now return groups in the order where the OS returns them,thanks to Gisle Aas. This wasn't previously the case.=head2 Recursive sort subsYou can now use recursive subroutines with sort(), thanks to Robin Houston.=head2 Exceptions in constant foldingThe constant folding routine is now wrapped in an exception handler, andif folding throws an exception (such as attempting to evaluate 0/0), perlnow retains the current optree, rather than aborting the whole program.Without this change, programs would not compile if they had expressions thathappened to generate exceptions, even though those expressions were in codethat could never be reached at runtime. (Nicholas Clark, Dave Mitchell)=head2 Source filters in @INCIt's possible to enhance the mechanism of subroutine hooks in @INC byadding a source filter on top of the filehandle opened and returned by thehook. This feature was planned a long time ago, but wasn't quite workinguntil now. See L<perlfunc/require> for details. (Nicholas Clark)=head2 New internal variables=over 4=item C<${^RE_DEBUG_FLAGS}>This variable controls what debug flags are in effect for the regularexpression engine when running under C<use re "debug">. See L<re> fordetails.=item C<${^CHILD_ERROR_NATIVE}>This variable gives the native status returned by the last pipe close,backtick command, successful call to wait() or waitpid(), or from the

⌨️ 快捷键说明

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