Trying Perl signatures


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


Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

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

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.