Trying Perl signatures

Software

Speaking of signatures, Perl 5.20 introduced the concept in an experimental feature in 2015, and I’m only just getting around to trying it. Prior we would have done this:

sub sumificate {
    my ($first, $second) = @_;
    return $first + $second;
}

Or this for a single parameter:

sub printificate {
    my $message = shift;
    return $message;
}

Now we can do this:

use feature qw(say signatures);
no warnings qw(experimental::signatures);    
    
sub sumificate($first, $second) {
    return $first + $second;
}

This is compatible with use strict, even without my on the parameters which is a nice shorthand. The script is in my lunchbox if you want to give it a try.

Author bio and support

Me!

Ruben Schade is a technical writer and IaaS engineer in Sydney, Australia who refers to himself in the third person in bios. Wait, not BIOS… my brain should be EFI by now.

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or buy some silly merch. Thanks!