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:

sub convert (:$from!, :$to!, :$thing!) { ... }
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.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }


Update: Added exclamation points. :$foo defaults to being optional.

In reply to Your named arguments by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.