Perl 5.38.0 Released - An Appeal To New Blood?
Written by Nikos Vaggalis   
Thursday, 06 July 2023

Perl, despite having fallen out of favor and tanking in terms of programming language popularity, still moves forward. It's business as usual with version 5. 38 just released.

Maybe, just maybe, the new features introduced into the language in this newest version will attract much sought new talent. Perl is a language that while it doesn't attract new blood, is nevertheless resilient and embraced by a community of developers who really know the reasons that make it worth sticking to.

Some of those reasons were nicely lined up in Why Perl?

  1. It is installed by default everywhere. I don’t need administrative privileges to deploy Perl code almost anywhere. That is extremely empowering.
  2. With a great amount of discipline, Perl scripts can be successfully scaled up into large, complex systems.
  3. I can be confident that a Perl script I write today will run unaltered 10 years from now, modulo external collaborators.
  4. Perl can be used nearly as a shell replacement for very quick scripting.
  5. Perl has a small set of core syntax and is very extensible and flexible in adopting new paradigms.

I would add at position 6-The fun factor.

Point number 5 is the one that gets the biggest revamping in this version, by the addition of the Class keyword. Yes, Perl while having always veen object-oriented for ever, officially gets classes:

It is a core implementation of the class syntax similar to the one you would find in other programming languages. It isn't a ??bless wrapper, but a completely new system built right into the Perl interpreter.

use v5. 38;
use feature 'class';
class My::Example 1. 234 {
  field $x;
  ADJUST {
     $x = "Hello, world";
  }
 method print_message {
   say $x;
  }
}
My::Example->new->print_message;

Because Perl was so lax about its Object Orientation paradigm, various attempts have been made to bring it close to par with the rest of the traditional OOP programming languages. The most notable of these attempts are Moose and Moo but there are others too hence creating an environment of deep fragmentation, aka not beginner friendly. As such Corrina can be also considered as an attempt to unify the Perl OO paradigm simplifying things and making the onboarding of newcomers wishing to get started with the language much easier and straightforward.

Moreover, now fields are visible in the scope of the class, with each class instance getting its own storage of them, independent of each other. That is private fields. To do the same the old Core way you had to implement your object as a closure. Hacky.

Note that the Class keyword is part of the plan to bring effective OOP to the Perl core while still keeping Perl being Perl, in an effort collectively known as Corinna. The Corinna MVP then, is being implemented in 7 steps :

  • Classes
  • Inheritance
  • Roles
  • Convenience attributes
  • Field initializer blocks
  • MOP
  • Method modifiers

version 5. 38 instills the first one into the Core.

However it remains an experimental feature, which is very much still under development and will be the subject of much further addition, refinement and alteration in future releases.

So while Class would be the most important addition to this version, there were other more minor ones but pretty interesting nevertheless. Amongst them are :

Support for Unicode 15
As always Perl is the first to catch up to the standard. Unicode 15. 0 adds 4, 489 characters, for a total of 149, 186 characters. These additions include 2 new scripts, for a total of 161 scripts, along with 20 new emoji characters, and 4, 193 CJK (Chinese, Japanese, and Korean) ideographs. By any means getting up to date with the standard is a feat by itself.

Defined-or and logical-or assignment default expressions in signatures
The default expression for a subroutine signature parameter can now be assigned using the //= or ||= operators, to apply the defaults whenever the caller provided an undefined or false value (respectively), rather than simply when the parameter is missing entirely.

Optimistic Eval in Patterns with the addition of (*{ . . . })
Certain types of optimizations are disabled when (?{ . . . }) or (??{ . . . }) is included in a pattern, so that patterns which are O(N) in normal use become O(N*N) with a (?{ . . . }) pattern in them. Switching to (*{ . . . }) means the pattern will stay O(N).

As a refresher, the (?{ . . . . }) construct essentially allows for embedding Perl code that gets executed upon every match of the pattern inside the regular expression.

While ??{. . . } is like a regular code expression, except that the result of the code evaluation is treated as a regular expression and matched immediately. Because a lot of black magic was happening behind the scenes in order for those to work, certain optimizations where turned off. Not anymore if you choose so.

Staying on the regex front, the next feature is a re-write to make its purpose cleaner. To reuse the last successful pattern match you would use the empty pattern. The following code: ??

if (m/foo/ || m/bar/) {
   s//PQR/;
}
can now be rewritten as follows
if (m/foo/ || m/bar/) {
   s/${^LAST_SUCCESSFUL_PATTERN}/PQR/;
}

making the intent clearer by deviating slightly from the "do what I mean" notion. It's little things like that that make a newcomer's onboarding easier.

On the depracations front, we find:

Use of ' as a package name separator is deprecated
Using ' as package separator in a variable named in a double-quoted string has ??warned since 5. 28. It is now deprecated in both string interpolation and non-interpolated contexts, and will be removed in Perl 5. 42.

It had never occurred to me to use ' as the package separator, resembling something like "package Super'Bike;". Seems something like that was always allowed.

Also, the battered "Switch and Smart Match" operator was finally deemed a failure and will be entirely removed from Perl in v5. 42. 0.

With the version, some core modules got updated to their newest counterparts too. Non inclusive list :

  • Data::Dumper has been upgraded from version 2.184 to 2.188.
  • Digest::SHA has been upgraded from version 6.02 to 6.04.
  • Encode has been upgraded from version 3.17 to 3.19.
  • File::Find has been upgraded from version 1.40 to 1.43.

For the full changelog check the latest perldelta.

 

More Information

Perl 5.38.0 perldelta

Why Perl?

 

Related Articles

It Was About Time To Find A Shared Vision Of The Perl Foundation

Perl 5.36 Released - What's New? 

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Looking Forward To NAO 7
03/11/2024

Introduced to the world in 2004 by its creator Bruno Maisonnier the kid-sized, autonomous humanoid robot NAO, turns 20 this year. At less than 2 ft tall, it is small in stature, but plays a big r [ ... ]



Sequin - Open Source Message Stream Built On Postgres
31/10/2024

Sequin is a tool for capturing changes and streaming data out of your Postgres database, guaranteeing exactly once processing. What does that mean?


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 06 July 2023 )