...I was wondering whether someone could enlighten as to which method is more efficient.What do you mean by "efficient"? Do you mean programmer efficiency, runtime efficiency, ease of maintenance, etc? There are many considerations regarding efficiency. One answer is not enough.
I'm wondering which is the method of choice, especially if I start passing roughly 6 params to packaged subroutines.If you're unsure of the number of params to pass, or if it's likely to change, consider using a hash or hash reference as the argument to the sub.
Consider:
This will flatten to a list. The actual sub looks like this:my $url = createReturnURL ( session => $session, host => $host, params => \@params );
With the arguments being passed as a hash, you are no longer forced to worry about the order of the arguments, and assigning default arguments in the actual subroutine is trivial. Further, extending the functionality of this subroutine is as simple as adding a new hash key and testing for its existence within the subroutine.sub createReturnURL { my %argument = @_; if ( exists $argument{ session } ) { # do something } # more code here }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In reply to (Ovid) Re: Most Efficient
by Ovid
in thread Most Efficient
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |