http://www.perlmonks.org?node_id=469106


in reply to Predefining sub Parameters

Hi

You're kinda stuck with the fact that all parameters to your sub are going to be passed in through @_. You can make the assignment the first thing you do in the sub, either by shifting or assigning.
sub functionname { my $string_param = shift; my $other_string_param = shift; my @array_param = @_ ; #-- the remnant after the first two are assign +ed #-- do edit check here, throw error #-- do rest of sub function }
or all at once
sub functionname { my ( $string_param, $other_string_param, @array_param ) = @_; #-- do edit check here, throw error #-- do rest of sub function }
note that if you want to pass in a mix of strings and an array, the array has to come last, as everything gets 'flattened' onto @_. If you want to pass in two or more arrays, or an array in the middle of your list, you need to use a reference.
sub functionname { my $string_param = shift; my $array_ref = shift; my @array = @{$array_ref}; my $other_string_param = shift; #-- do edit check here, throw error #-- do rest of sub function } #-- call as: sub functionname( $string_param, \@array_param, $other_string_param);
Finally, stay away from sub prototypes. Search the monastery for all the reasons why.

- j