Perl 5.20 Signatures in Subroutine References

Posted
Categories
post
Uses
perl
Tags
programming

Perl 5.20 has experimental support for function signatures. That’s good news. I just thought to check if signatures can be used in subroutine references. They can.

# Set a base set of features.
use 5.20.0;
# Signatures are experimental, so are not enabled by default.
use feature 'signatures';
# Otherwise Perl will warn about using the experimental feature
no warnings 'experimental::signatures';
sub hello($person) {
say "Hello, $person";
}
my $goodbye = sub($person) {
say "Goodbye, $person";
};
my $me = "Brian";
hello( $me );
$goodbye->( $me );

It’s a simple test. Just checking to see if I can maybe use this feature in my own projects.

Terminal window
$ perl sig-test.pl
Hello, Brian
Goodbye, Brian

This pleases me. It’s not going to make life easier for Pygments, though.