I am doing this mostly as a means to learn about prototyping, subroutines, and later, making modules.

The absolutely most important thing to learn about Perl's prototypes is that in most cases — almost all cases, really — they should not be used at all. They are not prototypes by any definition that you may be expecting if you came to Perl from another language.

Their primary reason for existing at all is to allow us to write subs that have the same semantics as some builtins. The ability to prototype a sub that takes a BLOCK can be used to extend the language syntax, but that's generally not a good idea anyway. An empty prototype can be a hint that the sub might be inlinable, which is nice and all but usually it's almost meaningless in terms of real performance.

Not only do Perl's prototypes fail to do what you expect, but they fail to do it in ways that can be real easy to trip over. If you haven't already read the link that BrowserUk gave you, read it now. In fact, even if you have already read it, read it again. And avoid prototypes until you really understand the issues involved. You'll be saving yourself headaches in the long run.

Update: Erk! Changed to reflect what I meant... I do not have some absurd prejudice against Perl's subroutines. :-) Thanks BrowserUk!

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Subroutine Prototyping/Subroutine Argument Parsing by sauoq
in thread Subroutine Prototyping/Subroutine Argument Parsing by Missing Words

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.