Perl v5.28 new features

Perl v5.28 is just getting started! » Read more…

Deprecation warnings now tell you when the features will disappear

Perl v5.28 will have better deprecation warnings. Most of this I picked up from the lightning talk that Abigail gave at The Perl Conference.

Perl 5, released in 1994, deprecated many things that it never removed. It’s over 20 years later and those things are still there. Even though they are deprecated they had no schedule for actual removal. The Perl 5 Porters are now paying attention to these things but following perlpolicy by removing them after two (or more) stable releases. Some things have been scheduled for particular releases as noted in perldeprecation. Similarly, you might be interested in perlexperiment

Consider the misfeature of an opening heredoc with no label:

use strict;
use warnings;

my $string = <<; This is the heredoc print $string; You get the warning: % perl5.8.9 bare-heredoc.pl Use of bare << to mean <<"" is deprecated This is the heredoc In the just released v5.26.0 the warning got a bit more interesting. The deprecations now have a schedule and the warnings note that: $ perl5.26.0 heredoc.pl Use of bare << to mean <<"" is deprecated. Its use will be fatal in Perl 5.28 at heredoc.pl line 5. This is the heredoc In v5.28 you'll need to use the quote marks: use strict; use warnings; my $string = <<''; This is the heredoc print $string; v5.27 already makes this fatal: $ perl5.27.2 -c heredoc.pl Use of bare << to mean <<"" is forbidden It might look odd to have no visible closer for the heredoc. But, here's a curious use in the new indented heredoc. With a zero-length delimiter and an indented closing line you have to be sure the whitespace stays in the file. I’ve used ⤷ to represent a tab:

use strict;
use warnings;

my $string = <<~''; ⤷ This is the heredoc ⤷ print $string; I've set my editor to automatically remove trailing whitespace. That will change the output of this program. But I don't plan on using a zero-length delimiter for my heredocs. I only know I can because Abigail gave a lightning talk about it.

You must escape the left brace in a regex

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.

{

» Read more…

/xx means more meaningless whitespace (and that’s good)

The /xx match operator flag lets you add insignificant horizontal whitespace to character classes. You’ll have to upgrade to v5.26 to use it though, but that release is right around the corner.

The /x has been around since v5.10. That allows you to spread out the parts of your pattern and to add internal comments. This flag makes horizontal whitespace insignificant.

» Read more…

v5.26 removes dot from @INC

As of v5.26, the . in @INC is gone by default. When you compile perl, it bakes the default module search path (based on your configure settings) into the binary. These are the paths that perl searches without you adding to @INC with command-line switches or environment variables, and the paths you see when you run perl -V:

» Read more…

Strip leading spaces from here-docs with v5.26

Perl v5.26 allows you to indent heredocs, that special multi-line string quoting mechanism. In v5.24 and earlier, the content of any here-doc included the entire line with any leading whitespace might be there. That meant you typed here-docs in a way the broke the indention of the block that contained them. Perl 6 envisioned a way that this could work and now Perl 5 has stolen some of that.

» Read more…

Perl v5.24 adds a line break word boundary

Perl v5.24 adds a linebreak word boundary, \b{lb}, to go along the new word boundaries added in v5.22. This is part of Perl’s increasing conformance with the regular expression requirements in Unicode Technical Standard #18. The Unicode::LineBreak implements the same thing, although you have to do a lot more work. » Read more…

Perl v5.22 adds fancy Unicode word boundaries

Perl v5.22’s regexes added four Unicode boundaries to go along with the vanilla “word” boundary, \b, that you’ve been using for years. These new assertions aren’t going to match perfectly with your expectations of human languages (the holy grail of natural language processing), but they do okay-ish. Although these appear in v5.22.0, as a late edition to the language they were partially broken in the initial release. They were fixed for v5.22.1. » Read more…

Perl v5.26 new features

Perl v5.26 has lots of improvements and some big changes with module loading. This might be the most backward-incompatible version this decade! » Read more…

Lexical $_ and autoderef are gone in v5.24

Two features that I have previously discouraged are now gone from Perl. The lexical $_ and auto dereferencing.

The lexical $_ was a consequence of the way Perl wanted smart match to work. In a given-when, instead of aliasing $_ like foreach does, the block had an implicit my $_ = .... This interfered with the package version, as I wrote about in Use for() instead of given() and Perl v5.16 now sets proper magic on lexical $_. » Read more…