I don't want a pony. Don't have a place to put it. Prettymuch anything you do with named parameters in Perl, except for requiring their use and forbiding positional parameters completely, is fragile in one way or another.

If by the better alternative you mean

foo( 1, 2, 3); foo({ one => 1, two => 2, three => 3}); #with or without dashes
then this is fragile if the first positional parameter may be a hashref.

Besides ... I would not feel guilty about that example ... that call doesn't look like a named-parameters call so it's not one. I can live with that. On the other hand if there was a way to distinguish between -foo and '-foo' that would work as well ... it's very unlikely that anyone would ever write $stringvar = -foo; or $stringvar = -$otherstring.

Apart from being unable to tell between one positional hashref and several named params in foo({ -one > 1, -two => 2}); there is one more reason I don't want to do that. With foo( inparam => 31, outparam => $var) I can modify the $var from within foo(), with foo({ inparam => 31, outparam => $var}) I could not. While mostly I do think that functions should take (readonly) parameters and return some value(s), if possible without side effects, in case the subroutine is a wrapper of a database's stored procedure without output parameters, I do need to allow that. And I do not really like foo({ inparam => 31, outparam => \$var}).


In reply to Re^2: -foo not readonly in fun(-foo => 1} in perl v5.8.7 (wishes) by Jenda
in thread -foo not readonly in fun(-foo => 1) in perl v5.8.7 by Jenda

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.