[Kc] subroutine parameter list
David Nicol
davidnicol at gmail.com
Wed Apr 9 14:14:11 PDT 2008
On Wed, Apr 9, 2008 at 2:39 PM, Kit Peters <popefelix at gmail.com> wrote:
> Is there some compelling reason you can't just pass your parameters as
> a hashref?
>
> param_test({tom => "somestring", george => "anotherstring", ref => \@array});
>
> sub param_test {
> my $args = shift;
> croak "Usage: param_test($hashref)" unless ref $args eq 'HASH';
> ....
>
>
> }
as I understand it the best practice for readability is
param_test(tom => "somestring", george => "anotherstring", ref => \@array);
sub param_test {
my %args = @_;
croak <<INSTRUCTIONS unless 3 == grep { exists $args{$_}} qw/tom george ref/;
please refer to thread on KCLUG mailing list
INSTRUCTIONS
...
}
--
bringing useful insights from Computer Science to the larger world
More information about the kc
mailing list