G'day andrewkl,
Welcome to the Monastery.
I think you're looking at this back-to-front.
Write your subroutines such that they read the arguments they need. E.g.
sub f { my ($AoH) = @_; for my $hashref (@$AoH) { # do something with $hashref } }
Then call those subroutines with the appropriate arguments. E.g.
... # somewhere in your code f($AoH); ... # elsewhere in your code f([$hashref1, $hashref2]); ... # and at some other point f([\%hash]); ...
As you can see from those examples, you can (often) create the argument list in situ.
What you really want to avoid is subroutine definitions like this:
sub g { my ($arrayref_containing_just_one_hashref) = @_; my $hashref = $arrayref_containing_just_one_hashref->[0]; # do something with $hashref }
So, get the subroutine definition right, then call as needed. If that requires some complex code to create the argument list, so be it.
— Ken
In reply to Re: Best practices for passing in function arguments?
by kcott
in thread Best practices for passing in function arguments?
by andrewkl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |