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””
Category: perl
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”
Perl 5.20 new features
Perl 5.20 is out and there are some nice syntax changes that make life easier for Perlers, along with some improvements that don’t require any work from you. Some of the features are experimental, so be careful that you don’t create problems by overusing them until they settle down.
You can download the Perl source from CPAN. For Windows, Strawberry Perl 5.20 is available now. The full details are in the perldelta Continue reading “Perl 5.20 new features”
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)”
Perl 5.18 new features
Perl v5.18 is out and there are some major changes that you should know about before you upgrade. Most notably, some features from v5.10 are now marked experimental. If you use those features, you get warnings.
You can download the Perl source from CPAN. For Windows, Strawberry Perl 5.18 is available now. Continue reading “Perl 5.18 new features”
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 $&
.