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

Perl 5.20 Signatures in Subroutine References

Tags: programming POST

Does any of this enlighten, entertain, or otherwise please you? Please consider a Tip. Every little bit helps!

I last updated this page

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.

Code Sample
    # 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.

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

  

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