Re: Are prototypes evil? has a pretty good explanation (as well as the discussion to same author's When to use Prototypes?). You can't reliably use prototypes for argument validation since that's not what they do; they only coerce the context the value is placed in. sub foo ($) doesn't mean that you can only call foo( $scalar ), but that whatever argument you do pass will be put in scalar context. That means that foo( bar() ) for some bar which is context sensitive isn't going to do what you expect unless you're intimately familiar with foo's prototype. No errors will be raised, no warnings will be generated, but the behavior will be different than the norm.

Or another example: given sub baz ($$$) and my @a = qw( a b c ), you can't just call baz( @a ) you have to explicitly write baz( $a[0], $a[1], $a[2] ). There's 3 arguments available, it may make perfect sense to keep them grouped in an array, but because of the prototype you've got to go through extra hoops and write more code.

This is why the conventional wisdom is to avoid them unless you're explicitly trying to mimic a builtin. If you want argument validation, there's better ways to do so.

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re^5: Can you tell what $$$\@ means? by Fletch
in thread Can you tell what $$$\@ means? by crusty_collins

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.