In-place editing is getting much safer in v5.28. Before that, in rare circumstances it could lose data. You may have never noticed the problem and even with all the times I’ve explained it in a Perl class I haven’t really thought about it. This was first reported as early as December 2002 and after we get v5.28 it won’t be a problem anymore. Continue reading “In-place editing gets safer in v5.28”
Category: miscellany
Beware of the removal of when in Perl v5.28
[Although I haven’t seen an official notice besides a git commit that reverts the changes, by popular outcry these changes won’t be in v5.28. It’s not that they won’t happen but they won’t be in v5.28. People who depend on Perl should stay vigilant. My advice in the first paragraph stands—change is coming and we don’t know what it is yet.]
Perl v5.28 might do away with when
—v5.27.7 already has. Don’t upgrade to v5.28 until you know you won’t be affected by this! This change doesn’t follow the normal Perl deprecation or experimental feature policy. If you are using given-when
, stop doing that. If you aren’t using it, don’t start. And everyone should consider if a major change like this on such short notice is comfortable for them. It’s not a democracy but you can still let the core developers know which way you want your favorite language to go.
Continue reading “Beware of the removal of when in Perl v5.28”
keys in scalar context now returns the number of keys
Starting in v5.26, a hash in scalar context evaluates to the number of keys in the hash. You might have thought that it always did that just like an array (not a list!) in scalar context evaluates to the number of items. But nope—it evaluated to a seemingly useless number called the “hash statistics”. Now it’s fixed to do what most people thought it already did. For what it’s worth, keys
(or values
) in scalar context already provided the count.
Continue reading “keys in scalar context now returns the number of keys”
Apple recommends installing your own perl
Apple recommends installing your own perl (or python or ruby) for your private development to not interfere with the work the bundled perl (or python or ruby) does. In Item 110. Compile and install your own perls. we recommended the same thing. Continue reading “Apple recommends installing your own perl”
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”
Use a computed label with loop controllers
Not sure which loop you want to break out of? Perl v5.18 makes that easy with computed labels. The value you give next
, last
, and redo
no longer has to be a literal. You could already do this with goto
, but now you can give the loop controllers an expression. Continue reading “Use a computed label with loop controllers”
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”
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”
The Perl 5.12 yada yada operator
Perl v5.12 adds a placeholder operator, ...
, called the yada yada operator, after an episode of Seinfeld where the interesting parts of the story are replaced with “yada yada yada”. Continue reading “The Perl 5.12 yada yada operator”
Create your own dualvars
Perl’s basic data type is the scalar, which takes its name from the mathematical term for “single item”. However, the scalar is really two things. You probably know that a scalar can be either a number or a string, or a number that looks the same as its string, or a string that can be a number. What you probably don’t know is that a scalar can be two separate and unrelated values at the same time, making it a dualvar. Continue reading “Create your own dualvars”