saintmike,
I have been meaning to reply to this node but I kept getting distracted.

Argument handling is one of those deceptively difficult things to do right. If you assume that your well documented API is being followed, you can probably get away with a few lines of code as you demonstrate here. The difficulty arises when you decide to handle input you don't expect. Imagine how your code would break if an uneven number of elements were passed. It can be easily remedied.

croak "Incorrect number of parameters" if @_ % 2;

Of course this is only one kind of issue that may need to be handled. There are a myriad of potential smoking guns.

This is by far not an exhaustive list. As you can see, this can be a daunting task. That is one reason why there are a plethora of modules on CPAN. Another reason is there are many schools of thought on how to handle the issues.

There is nothing wrong with the solution you presented but it ends up producing the same underlying data structure that the Anonymous Monk indicates is undesired. I find it suspicious that there is no reason given why the obvious solution key => [$val1, $val2, $val3] is unwanted.

In any account, I wanted to take this opportunity to shed some light on the complexity of this seemingly simple problem.

Cheers - L~R


In reply to Re^2: How to process named parameters that have the same key name? by Limbic~Region
in thread How to process named parameters that have the same key name? by Anonymous Monk

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.