CUFP
Super Monkey
snippet
<div class="Description">This subroutine allows you to pass parameters in any order and provide default values. Those of you who are familiar with something like this; my ($p0,$p1) = @{{@_}}{qw/p0 p1/},
will find this as an extention to it's functionality.
You must supply a default value for each expected input parameter, even if it is null, and the order of the parameters to subParams matters.</div>
<CODE>
sub subParams {
my %parameters = @{shift(@_)};
my @ret = ();
while (my ($entry,$default) = splice(@_,0,2)) {
if(length $parameters{$entry}) {
push(@ret,$parameters{$entry});
}
else {
push(@ret,$default);
}
}
@ret;
}
sub sample {
my ($p0,$p1) = subParams(\@_,p0=>'d0',p1=>'d1');
}
#With the above code, each of these calls are indentical
sample(p0=>'d0',p1=>'d1');
sample(p1=>'d1',p0=>'d0');
sample(p0=>'d0');
sample(p1=>'d1');
sample();
</CODE>