Perl v5.20 continues to clean up and optimize its internals. Now perl
optimizes a series of lexical variable declarations into a single list declaration. Continue reading “Perl v5.20 combines multiple my() statements”
Category: book
In v5.20, -F implies -a implies -n
Perl was once known for its one-liners in its sysadmin heydays. People would pass around lists of these one liners, many of which replaced complicated pipelines that glued together various unix utilities to do some impressive system maintenance. Continue reading “In v5.20, -F implies -a implies -n”
Perl 5.20 introduces “Key/Value Slices”
Perl v5.20 adds the “Key/Value Slice”, which extracts multiple keys and their corresponding values from a container (hash or array). It uses the %
, which is new, legal syntax for a variable name with subscripts after it: Continue reading “Perl 5.20 introduces “Key/Value Slices””
Perl 5.20 optimizes return at the end of a subroutine
Want to save 10 nanoseconds? Perl v5.20 optimizes a return
at the end of a subroutine to use two fewer ops in the optimized version. During compilation, a subroutine like this one: Continue reading “Perl 5.20 optimizes return at the end of a subroutine”
Perl 5.20 uses its own random number generator
Prior to v5.20, perl
used whatever random number generator the system provided. This meant that the same program could have statistically different results based on the quality of that function. The rand()
for Windows had a max of 32,768 (15 bits), while POSIX has drand48
(48 bits). This sort of numerical un-portability has always been a problem with perl
since it’s relied on the underlying libc for so much. Continue reading “Perl 5.20 uses its own random number generator”
Declare packages outside of their block
Perl v5.14 gets a step closer to a saner way to declare classes with its new package NAME BLOCK
syntax that lets you easily group everything that goes in a package. Continue reading “Declare packages outside of their block”
Experimental features now warn (reaching back to v5.10)
Perl 5.18 provides a new way to introduce experimental features in a program, augmenting the feature pragma that v5.10 added. This change marks certain broken v5.10 features as experimental with an eye toward possible removal from the language.
Smart matching in v5.10 led to several broken and conflated features. The given
used a lexical version of $_
, which broke many other common uses of that variable inside the given
, which I explain in Use for() instead of given() and you can see in given/when and lexical $_ …. Continue reading “Experimental features now warn (reaching back to v5.10)”
The vertical tab is part of \s in Perl 5.18
Up to v5.18, the vertical tab wasn’t part of the \s
character class shortcut for ASCII whitespace. No one really knows why. It was curious trivia that I pointed out in Know your character classes under different semantics. Whitespace in ASCII, POSIX, and Unicode represented different sets. Perl whitespace was different from POSIX whitespace by only the exclusion of the vertical tab. Now that little oversight is fixed. Continue reading “The vertical tab is part of \s in Perl 5.18”
Perl v5.12 adds the package NAME VERSION syntax
Perl v5.12 modifies the package
statement to take a version as well as a name. This allows you to implicitly declare the $VERSION
variable: Continue reading “Perl v5.12 adds the package NAME VERSION syntax”
Ignore part of a substitution’s match
Normally, a substitution replaces everything it matched, but v5.10 adds a feature that allows you to ignore part of the match. The \K
excludes from $&
anything to its left. This feature has already made it into PCRE. It doesn’t have an official name, so I’ll call it the match reset operator because it resets the start of $&
.