Collecting my attempts to improve at tech, art, and life

Perl 5.20 Signatures in Subroutine References

Tags: perl 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.

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

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


Added to vault 2024-01-15. Updated on 2024-01-26