5.20的新特性很多,比如:
Experimental Subroutine signatures
Declarative syntax to unwrap argument list into lexical variables. sub foo ($a,$b) {...} checks the number of arguments and puts the arguments into lexical variables. Signatures are not equivalent to the existing idiom of sub foo { my($a,$b) = @_; ... }. Signatures are only available by enabling a non-default feature, and generate warnings about being experimental. The syntactic clash with prototypes is managed by disabling the short prototype syntax when signatures are enabled.
See "Signatures" in perlsub for details.
subs now take a prototype attribute
When declaring or defining a sub, the prototype can now be specified inside of a prototype attribute instead of in parens following the name.
For example, sub foo($$){} could be rewritten as sub foo : prototype($$){}.
More consistent prototype parsing
Multiple semicolons in subroutine prototypes have long been tolerated and treated as a single semicolon. There was one case where this did not happen. A subroutine whose prototype begins with "*" or ";*" can affect whether a bareword is considered a method name or sub call. This now applies also to ";;;*".
Whitespace has long been allowed inside subroutine prototypes, so sub( $ $ ) is equivalent to sub($$), but until now it was stripped when the subroutine was parsed. Hence, whitespace was not allowed in prototypes set by Scalar::Util::set_prototype. Now it is permitted, and the parser no longer strips whitespace. This means prototype &mysub returns the original prototype, whitespace and all.
rand now uses a consistent random number generator
Previously perl would use a platform specific random number generator, varying between the libc rand(), random() or drand48().
This meant that the quality of perl's random numbers would vary from platform to platform, from the 15 bits of rand() on Windows to 48-bits on POSIX platforms such as Linux with drand48().
Perl now uses its own internal drand48() implementation on all platforms. This does not make perl's rand cryptographically secure. [perl #115928]
New slice syntax
The new %hash{...} and %array[...] syntax returns a list of key/value (or index/value) pairs. See "Key/Value Hash Slices" in perldata. |