Skip to content

Instantly share code, notes, and snippets.

@manwar
Created February 10, 2025 18:49
Show Gist options
  • Save manwar/b7579bf6ba2b8aa05434972d2beb03a3 to your computer and use it in GitHub Desktop.
Save manwar/b7579bf6ba2b8aa05434972d2beb03a3 to your computer and use it in GitHub Desktop.
Perl v5.41 changes.

The details can be found in the delta pod.

Core Enhancements

#1: New :writer attribute on field variables.

#!/usr/bin/env perl

use v5.41;
use experimental 'class';

class Point {
    field $x :reader :writer :param;
    field $y :reader :writer :param;
}

my $p = Point->new( x => 20, y => 40 );
say $p->x;       # reader
$p->set_x(30);   # writer
say $p->x;       # reader  

Run the code now:

$ p541 class-v541.pl
20
30
$
#2: New any and all operators

#!/usr/bin/env perl

use v5.41;
use experimental qw/all any/;

if (all { $_ % 2 == 0 } (2, 4, 6)) {
    say "All the numbers are even.";
}

if (any { $_ % 2 == 0 } (2, 3, 4)) {
    say "Some numbers are even.";
}

Run the code now:

$ p541 all-any-v541.pl
All the numbers are even.
Some numbers are even.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment