DavidSzczesniak
12/14/2017 - 2:39 PM

Function Signatures

This built-in function offers many features that can shorten and simplify alot of code.

use experimental 'signatures;

# You can now write:
sub greet_one($name) {
  say "Hello, $name!";
}

# As opposed to:
sub greet_one {
  die "Too many arguments for subroutine" if @_ < 1;
  die "Too few arguments for subroutine" if @_ > 1;
  my $name = shift;
  say "Hello, $name";
}

# Other parameter handling distributions include Method::Signatues which works as far back as 5.8 and Kavorka that works with 5.14 and newer.