in reply to Re: How to process named parameters that have the same key name?
in thread How to process named parameters that have the same key name?

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