Perl’s dereferencing syntax might be, or even should be, responsible for people’s disgust at the language. In v5.20, Perl added the experimental postfix dereferencing syntax that made this analogous to method chaining. This is one of the most pleasing Perl features I’ve encountered in years. Continue reading “Postfix dereferencing is stable is v5.24”
Category: perl
No more -no_match_vars
The English module translates Perl’s cryptic variable names to English equivalents. For instance, $_
becomes $ARG
. This means that the match variable $&
becomes $MATCH
. This also means that using the English module triggered the performance issue associated with the match variables $`
, $&
, and $'
even if you didn’t use those variables yourself—the module used them for you. The Devel::NYTProf debugger had a sawampersand
feature to tell you one of those variables appeared in the code. We covered this in Item 33. Watch out for the match variables. Continue reading “No more -no_match_vars”
Perl v5.24 new features
Perl v5.24 may not look like it’s packed full of exciting features (indeed, it removes some of them) but it has lots of improvements under the hood. Here’s some of the user-visible features you might like. Continue reading “Perl v5.24 new features”
Use /aa to get ASCII semantics in regexes, for reals this time
When Perl made regexes more Unicode aware, starting in v5.6, some of the character class definitions and match modifiers changed. What you expected to match \d
, \s
, or \w
are more expanvise now (Know your character classes under different semantics). Most of us probably didn’t notice because the range of our inputs is limited. Continue reading “Use /aa to get ASCII semantics in regexes, for reals this time”
Create named variable aliases with ref aliasing
Perl v5.22’s experimental refaliasing
feature adds the ability to alias a named variable to another named variable, or alias a named variable to a reference. This doesn’t copy the data; you end up with another named variable for the same data. As with all such features, the details and syntax may change or the feature may be removed all together (according to perlpolicy). Update: Also see v5.26’s declared_refs
experimental feature.
Continue reading “Create named variable aliases with ref aliasing”
Make bitwise operators always use numeric context
[This feature is no longer experimental, starting in v5.28. Declaring use 5.28
automatically enables them.]
Most Perl operators force their context on the values. For example, the numeric addition operator, +
, forces its values to be numbers. To “add” strings, you use a separate operator, the string concatenation operator, .
(which looks odd at the end of a sentence).
The bitwise operators, however, look at the value to determine their context. With a lefthand value that has a numeric component, the bitwise operators do numeric things. With a lefthand value that’s a string, the bit operators become string operators. That’s certainly one of Perl’s warts, which I’ll fix at the end of this article with a new feature from v5.22. Continue reading “Make bitwise operators always use numeric context”
Perl v5.22 adds hexadecimal floating point literals
You can specify literal hexadecimal floating-point numbers in v5.22, just as you can in C99, Java, Ruby, and other languages do. Perl, which uses doubles to store floating-point numbers, can represent a limited set of values. Up to now, you’ve had to specify those floating point numbers in decimal, hoping that a double could exactly represent that number. That hope, sometimes unfounded, is the basis for the common newbie question about floating point errors. Continue reading “Perl v5.22 adds hexadecimal floating point literals”
Use Perl 5.22’s <<>> operator for safe command-line handling
We’ve had the three argument open
since Perl 5.6. This allows you to separate the way you want to interact with the file from the filename.
Old Perl requires you to include the mode and filename together, giving Perl the opportunity to interpret what you mean: Continue reading “Use Perl 5.22’s <<>> operator for safe command-line handling”
Perl 5.22 new features
The first Perl 5.22 release candidate is out and there are some new operators and many enhancements to regular expressions that look interesting, 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. Continue reading “Perl 5.22 new features”
Use v5.20 subroutine signatures
This is a chapter in Perl New Features, a book from Perl School that you can buy on LeanPub or Amazon. Your support helps me to produce more content.
This feature was promoted to a stable version in v5.36.
Subroutine signatures, in a rudimentary form, have shown up in Perl v5.20 as an experimental feature. After a few of years of debate and a couple of competing implementations, we have something we can use. And, because it was such a contentious subject, it got the attention a new feature deserves. They don’t have all the features we want (notably type and value constraints), but Perl is in a good position to add those later. Continue reading “Use v5.20 subroutine signatures”