Initialize array and hash variables with state

Perl v5.28 allows you to initialize array and hash variables that you declare with state. This is a feature a long time coming and that I’m quite happy as finally arrived.

Since v5.10 and up to v5.26 you could only initialize a state variable if it was a scalar. You could declare a hash or array variable but you couldn’t give it an initial value at the same time. You could do this:

Continue reading “Initialize array and hash variables with state”

Perl v5.26 now recognizes version control conflict markers

Perl v5.26 can now detect and warn you about a version control conflict markers in your code. In prior versions, the compiler would try to interpret those as code and would complain about a syntax error. You program still fails to compile but you get a better error message. Maybe some future Perl will bifurcate the program, run both versions, and compare the results (don’t hold your breath):

Continue reading “Perl v5.26 now recognizes version control conflict markers”

Unquoted empty heredoc terminators are now fatal

Continuing its quest to clean up long deprecated features, v5.28 takes care of another feature deprecated since v5.0. You can no longer neglect to specify a heredoc separator. This was a warning in v5.26 and is now fatal. You probably weren’t doing this anyway (I’ve never seen it in the wild), but it’s nice to know the edge cases are disappearing.

Continue reading “Unquoted empty heredoc terminators are now fatal”

In-place editing gets safer in v5.28

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”

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”

You must escape the left brace in a regex

Update: v5.30 brings this back. The exceptions to allow people to catch up should have already been fixed.

In v5.26 and later, you have to escape the left brace, {, in Perl regular expressions. You probably never thought about this overworked character, but lots of other people have. This is an important change because it’s a fatal issue that may cause your modules and other tools (such as an old version of autoconf!) to stop working. But, we’ve also known about this for a bit, so if you are up-to-date, things may have already been fixed.

{

Continue reading “You must escape the left brace in a regex”