Should a subroutine croak when called with more arguments than expected or should the extra arguments simply be ignored?
#!/usr/bin/env perl
use warnings;
use strict;
sub routine {
my ( $a, $b ) = @_;
return $a * $b;
}
my $reslult = routine( 4, 5, 6 );
Generally I don’t bother writing argument checks by hand, but I think the correct response is to croak. That way you can extend the function to take optional arguments later without breaking existing callers.
If your Perl is new enough, you can install and use
Function::Parameterslike this:(Btw, don’t call your variables
$aor$b: those names are used bysortand exempt fromstrict 'vars'checks.)