Your named argumentsby Juerd (Abbot)
|on Nov 07, 2005 at 21:07 UTC||Need Help??|
See this as a poll, but also as a request for discussion. If I've missed a previous thread, please let me know.
How do you do named arguments in Perl 5?
Do you use a hash? A module to check things? Maybe a source filter? Do warn or die or do nothing at all, in case of unknown keys?
Please provide an example of how you would handle this contrived and simple case, as a teaser presented in Perl 6:
The sub &convert requires exactly three named arguments (as indicated by the colons): from, to, and thing. They have to be specified (as indicated by the exclamation points), but may be undef. Of course, if you don't check for these things usually, don't include checks in your example. Here, the arguments are accessible through $from, $to and $thing in the sub itself, but if you access things through a hash, leave it that way.
If you use a hash, what is it called? arg? argv? args? param? params? %_? Is it copied from @_, or do you require the caller to pass a reference? Do you allow both?
It'll be interesting to see the colorful spectrum of what we all use.
Update: Added exclamation points. :$foo defaults to being optional.