Thursday, November 17, 2011

How to pass optional parameters to a Perl function?

You can use a semicolon in the prototype to indicate the end of the required parameters:

sub someFunction($$;$) {
  my ( $oblig_param1, $oblig_param2, $option_param ) = @_;
  ...
}
 
The ; is optional before a @ or %, which, according to the docs, "gobbles up everything else".

No comments: