Perl v5.40.0 Shows That It Is Too Resilient To Die
Written by Nikos Vaggalis   
Monday, 01 July 2024

Having faced doubt, debate and insecurity, Perl is still going after all those years, alive, kicking and making releases. Business as usual.

The latest release of 5.40.0, went out on June 9th in a cumulative effort by the Perl 5 maintainers team. It comes with some new features and some others which matured into production status.

The key ones are:

  • try/catch is no longer experimental
  • __CLASS__
  • ^^ logical xor operator
  • for, iterating over multiple values at a time

Let's take a better look.

Try/catch was introduced in Perl 5.34 as:

use feature 'try';

try {
   . . .
}
catch ( $e ) {
  . . .
}

Version 5.36 completed it by adding the finally() block too. This brought it up to par with the rest of the OOP languages in terms of structured exception handling. However the feature was experimental which now moves out of and into production.

The __CLASS__ keyword

Perl officially got Classes in the core by implementing the coresponding OO syntax similar to the one you would find in other OOP programming languages.

This was too introduced experimentally at an earlier version, that of 5.38.

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;

The new addition is that of the __CLASS__ token which when invoked within a method, or similar location, such as a field initializer expression, it returns the name of the class of the invoking instance. Essentially it is equivalent to ref($self) except that it can additionally be used in a field initializer to gain access to class methods, before the instance is fully constructed.

use feature 'class';

class Example1 {
     field $f = __CLASS__->default_f;
    sub default_f { 10 }
}

Since the talk is on Classes, there's been even further enchantments with the introduction of the
:reader attribute. When decorating a member variable it automatically generates an Accessor named after it.
That is:

field $name :reader;

is equivalent to

field $name;
method name () { return $name; }

If you're familiar with Moose this would look like:

use Moose;
has 'name' => ( is => 'ro' );

The ^^ operator

Adding to the set of && and || operators, comes the new exclusive-or operator:

$x ^^ $y and say "One of x or y is true, but not both";

Just a utility feature to simplify some operations.

Next, for, iterating over multiple values at a time is no longer experimental. That means that you can now do :

for my ($a, $b) ("apple", "banana", "orange", "lemon") {
    say $a, $b;
}

Finally, the builtin::inf, builtin::nan constants have been introduced which are equivalent to special floating point values infinity and Not a Number.

These were the main additions. Of course there's always the usual bug fixes, CVE patching and performance improvements.

Perl, is proven too resilient to die!

 

More Information

Perl 5.40.0 delta

Related Articles

Perl 5.38.0 Released - An Appeal To New Blood?

 

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


Microsoft Introduces Vector Abstractions Library For .NET
21/11/2024

Microsoft has announced a preview release of the Microsoft Extensions VectorData Abstractions library, which can be used to help integrate vector stores into .NET applications and libraries.



Use Javascriptmas To Hone Your Webdev Skills
08/12/2024

Every day until December 24th MDN, in partnership with Scrimba, is releasing a daily challenge, which as the name suggests requires you to practice your JavaScript skills. Each solution you submi [ ... ]


More News

espbook

 

Comments




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

Last Updated ( Wednesday, 03 July 2024 )