📄 perl56delta.pod
字号:
=head2 File globbing implemented internallyPerl now uses the File::Glob implementation of the glob() operatorautomatically. This avoids using an external csh process and theproblems associated with it. NOTE: This is currently an experimental feature. Interfaces and implementation are subject to change.=head2 Support for CHECK blocksIn addition to C<BEGIN>, C<INIT>, C<END>, C<DESTROY> and C<AUTOLOAD>,subroutines named C<CHECK> are now special. These are queued up duringcompilation and behave similar to END blocks, except they are called atthe end of compilation rather than at the end of execution. They cannotbe called directly.=head2 POSIX character class syntax [: :] supportedFor example to match alphabetic characters use /[[:alpha:]]/.See L<perlre> for details.=head2 Better pseudo-random number generatorIn 5.005_0x and earlier, perl's rand() function used the C libraryrand(3) function. As of 5.005_52, Configure tests for drand48(),random(), and rand() (in that order) and picks the first one it finds.These changes should result in better random numbers from rand().=head2 Improved C<qw//> operatorThe C<qw//> operator is now evaluated at compile time into a true listinstead of being replaced with a run time call to C<split()>. Thisremoves the confusing misbehaviour of C<qw//> in scalar context, whichhad inherited that behaviour from split().Thus: $foo = ($bar) = qw(a b c); print "$foo|$bar\n";now correctly prints "3|a", instead of "2|a".=head2 Better worst-case behavior of hashesSmall changes in the hashing algorithm have been implemented inorder to improve the distribution of lower order bits in thehashed value. This is expected to yield better performance onkeys that are repeated sequences.=head2 pack() format 'Z' supportedThe new format type 'Z' is useful for packing and unpacking null-terminatedstrings. See L<perlfunc/"pack">.=head2 pack() format modifier '!' supportedThe new format type modifier '!' is useful for packing and unpackingnative shorts, ints, and longs. See L<perlfunc/"pack">.=head2 pack() and unpack() support counted stringsThe template character '/' can be used to specify a counted stringtype to be packed or unpacked. See L<perlfunc/"pack">.=head2 Comments in pack() templatesThe '#' character in a template introduces a comment up toend of the line. This facilitates documentation of pack()templates.=head2 Weak referencesIn previous versions of Perl, you couldn't cache objects so asto allow them to be deleted if the last reference from outside the cache is deleted. The reference in the cache would hold areference count on the object and the objects would never bedestroyed.Another familiar problem is with circular references. When anobject references itself, its reference count would never godown to zero, and it would not get destroyed until the programis about to exit.Weak references solve this by allowing you to "weaken" anyreference, that is, make it not count towards the reference count.When the last non-weak reference to an object is deleted, the objectis destroyed and all the weak references to the object areautomatically undef-ed.To use this feature, you need the Devel::WeakRef package from CPAN, whichcontains additional documentation. NOTE: This is an experimental feature. Details are subject to change. =head2 Binary numbers supportedBinary numbers are now supported as literals, in s?printf formats, andC<oct()>: $answer = 0b101010; printf "The answer is: %b\n", oct("0b101010");=head2 Lvalue subroutinesSubroutines can now return modifiable lvalues.See L<perlsub/"Lvalue subroutines">. NOTE: This is an experimental feature. Details are subject to change.=head2 Some arrows may be omitted in calls through referencesPerl now allows the arrow to be omitted in many constructsinvolving subroutine calls through references. For example,C<< $foo[10]->('foo') >> may now be written C<$foo[10]('foo')>.This is rather similar to how the arrow may be omitted fromC<< $foo[10]->{'foo'} >>. Note however, that the arrow is stillrequired for C<< foo(10)->('bar') >>.=head2 Boolean assignment operators are legal lvaluesConstructs such as C<($a ||= 2) += 1> are now allowed.=head2 exists() is supported on subroutine namesThe exists() builtin now works on subroutine names. A subroutineis considered to exist if it has been declared (even if implicitly).See L<perlfunc/exists> for examples.=head2 exists() and delete() are supported on array elementsThe exists() and delete() builtins now work on simple arrays as well.The behavior is similar to that on hash elements.exists() can be used to check whether an array element has beeninitialized. This avoids autovivifying array elements that don't exist.If the array is tied, the EXISTS() method in the corresponding tiedpackage will be invoked.delete() may be used to remove an element from the array and returnit. The array element at that position returns to its uninitializedstate, so that testing for the same element with exists() will returnfalse. If the element happens to be the one at the end, the size ofthe array also shrinks up to the highest element that tests true forexists(), or 0 if none such is found. If the array is tied, the DELETE() method in the corresponding tied package will be invoked.See L<perlfunc/exists> and L<perlfunc/delete> for examples.=head2 Pseudo-hashes work betterDereferencing some types of reference values in a pseudo-hash,such as C<< $ph->{foo}[1] >>, was accidentally disallowed. This hasbeen corrected.When applied to a pseudo-hash element, exists() now reports whetherthe specified value exists, not merely if the key is valid.delete() now works on pseudo-hashes. When given a pseudo-hash elementor slice it deletes the values corresponding to the keys (but not the keysthemselves). See L<perlref/"Pseudo-hashes: Using an array as a hash">.Pseudo-hash slices with constant keys are now optimized to array lookupsat compile-time.List assignments to pseudo-hash slices are now supported.The C<fields> pragma now provides ways to create pseudo-hashes, viafields::new() and fields::phash(). See L<fields>. NOTE: The pseudo-hash data type continues to be experimental. Limiting oneself to the interface elements provided by the fields pragma will provide protection from any future changes.=head2 Automatic flushing of output buffersfork(), exec(), system(), qx//, and pipe open()s now flush buffersof all files opened for output when the operation was attempted. Thismostly eliminates confusing buffering mishaps suffered by users unawareof how Perl internally handles I/O.This is not supported on some platforms like Solaris where a suitablycorrect implementation of fflush(NULL) isn't available.=head2 Better diagnostics on meaningless filehandle operationsConstructs such as C<< open(<FH>) >> and C<< close(<FH>) >>are compile time errors. Attempting to read from filehandles thatwere opened only for writing will now produce warnings (just aswriting to read-only filehandles does).=head2 Where possible, buffered data discarded from duped input filehandleC<< open(NEW, "<&OLD") >> now attempts to discard any data thatwas previously read and buffered in C<OLD> before duping the handle.On platforms where doing this is allowed, the next read operationon C<NEW> will return the same data as the corresponding operationon C<OLD>. Formerly, it would have returned the data from the startof the following disk block instead.=head2 eof() has the same old magic as <>C<eof()> would return true if no attempt to read from C<< <> >> hadyet been made. C<eof()> has been changed to have a little magic of itsown, it now opens the C<< <> >> files.=head2 binmode() can be used to set :crlf and :raw modesbinmode() now accepts a second argument that specifies a disciplinefor the handle in question. The two pseudo-disciplines ":raw" and":crlf" are currently supported on DOS-derivative platforms.See L<perlfunc/"binmode"> and L<open>.=head2 C<-T> filetest recognizes UTF-8 encoded files as "text"The algorithm used for the C<-T> filetest has been enhanced tocorrectly identify UTF-8 content as "text".=head2 system(), backticks and pipe open now reflect exec() failureOn Unix and similar platforms, system(), qx() and open(FOO, "cmd |")etc., are implemented via fork() and exec(). When the underlyingexec() fails, earlier versions did not report the error properly,since the exec() happened to be in a different process.The child process now communicates with the parent about theerror in launching the external command, which allows theseconstructs to return with their usual error value and set $!.=head2 Improved diagnosticsLine numbers are no longer suppressed (under most likely circumstances)during the global destruction phase.Diagnostics emitted from code running in threads other than the mainthread are now accompanied by the thread ID.Embedded null characters in diagnostics now actually show up. Theyused to truncate the message in prior versions.$foo::a and $foo::b are now exempt from "possible typo" warnings onlyif sort() is encountered in package C<foo>.Unrecognized alphabetic escapes encountered when parsing quoteconstructs now generate a warning, since they may take on newsemantics in later versions of Perl.Many diagnostics now report the internal operation in which the warningwas provoked, like so: Use of uninitialized value in concatenation (.) at (eval 1) line 1. Use of uninitialized value in print at (eval 1) line 1.Diagnostics that occur within eval may also report the file and linenumber where the eval is located, in addition to the eval sequencenumber and the line number within the evaluated text itself. Forexample: Not enough arguments for scalar at (eval 4)[newlib/perl5db.pl:1411] line 2, at EOF=head2 Diagnostics follow STDERRDiagnostic output now goes to whichever file the C<STDERR> handleis pointing at, instead of always going to the underlying C runtimelibrary's C<stderr>.=head2 More consistent close-on-exec behaviorOn systems that support a close-on-exec flag on filehandles, theflag is now set for any handles created by pipe(), socketpair(),socket(), and accept(), if that is warranted by the value of $^Fthat may be in effect. Earlier versions neglected to set the flagfor handles created with these operators. See L<perlfunc/pipe>,L<perlfunc/socketpair>, L<perlfunc/socket>, L<perlfunc/accept>,and L<perlvar/$^F>.=head2 syswrite() ease-of-useThe length argument of C<syswrite()> has become optional.=head2 Better syntax checks on parenthesized unary operatorsExpressions such as: print defined(&foo,&bar,&baz); print uc("foo","bar","baz"); undef($foo,&bar);used to be accidentally allowed in earlier versions, and producedunpredictable behaviour. Some produced ancillary warningswhen used in this way; others silently did the wrong thing.The parenthesized forms of most unary operators that expect a singleargument now ensure that they are not called with more than oneargument, making the cases shown above syntax errors. The usualbehaviour of: print defined &foo, &bar, &baz; print uc "foo", "bar", "baz"; undef $foo, &bar;remains unchanged. See L<perlop>.=head2 Bit operators support full native integer widthThe bit operators (& | ^ ~ << >>) now operate on the full nativeintegral width (the exact size of which is available in $Config{ivsize}).For example, if your platform is either natively 64-bit or if Perlhas been configured to use 64-bit integers, these operations applyto 8 bytes (as opposed to 4 bytes on 32-bit platforms).For portability, be sure to mask off the excess bits in the result ofunary C<~>, e.g., C<~$x & 0xffffffff>.=head2 Improved security featuresMore potentially unsafe operations taint their results for improvedsecurity.The C<passwd> and C<shell> fields returned by the getpwent(), getpwnam(),and getpwuid() are now tainted, because the user can affect their ownencrypted password and login shell.The variable modified by shmread(), and messages returned by msgrcv()(and its object-oriented interface IPC::SysV::Msg::rcv) are also tainted,because other untrusted processes can modify messages and shared memorysegments for their own nefarious purposes.=head2 More functional bareword prototype (*)Bareword prototypes have been rationalized to enable them to be usedto override builtins that accept barewords and interpret them ina special way, such as C<require> or C<do>.Arguments prototyped as C<*> will now be visible within the subroutineas either a simple scalar or as a reference to a typeglob.See L<perlsub/Prototypes>.=head2 C<require> and C<do> may be overriddenC<require> and C<do 'file'> operations may be overridden locallyby importing subroutines of the same name into the current package (or globally by importing them into the CORE::GLOBAL:: namespace).Overriding C<require> will also affect C<use>, provided the overrideis visible at compile-time.See L<perlsub/"Overriding Built-in Functions">.=head2 $^X variables may now have names longer than one characterFormerly, $^X was synonymous with ${"\cX"}, but $^XY was a syntaxerror. Now variable names that begin with a control character may bearbitrarily long. However, for compatibility reasons, these variablesI<must> be written with explicit braces, as C<${^XY}> for example.C<${^XYZ}> is synonymous with ${"\cXYZ"}. Variable names with morethan one control character, such as C<${^XY^Z}>, are illegal.The old syntax has not changed. As before, `^X' may be either aliteral control-X character or the two-character sequence `caret' plus`X'. When braces are omitted, the variable name stops after thecontrol character. Thus C<"$^XYZ"> continues to be synonymous withC<$^X . "YZ"> as before.As before, lexical variables may not have names beginning with controlcharacters. As before, variables whose names begin with a controlcharacter are always forced to be in package `main'. All such variablesare reserved for future extensions, except those that begin with
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -