Trying Perl signatures
SoftwareSpeaking 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.