If you want named parameters, I'd suggest using the first method. If you want to operate on data stored in a hash, pass a hash ref. I don't like the idea of using a hash reference to pass in named parameters because the calls will mostly have those ugly additional braces.
I think a better question might be, "when should I use named parameters?"
My thoughts on that are that they should only be used where the parameters in question set features of a fairly complex datatype. Some examples:
my $shape = Box->new(length=>10, width=>5, height=>3); # might make s +ense. my $string = SuperString->new(text=>"foobar"); # probably doe +sn't. my $substr = mysubstr(Search=>"bigbigstring",For=>"big", Occurence=>2) +; # UGLY!
I've actually seen interns, apparently far too impressed with CGI.pm, write code like the third example. Please don't.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: What's your favorite method of passing parameters into a sub?
by sauoq
in thread What's your favorite method of passing parameters into a sub?
by jk2addict
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |