Do be careful with using prototypes vs. passing references. IMHO, code is much more readable and maintainable if you make a habit of passing references. In this manner, you don't have to look at the subroutine declaration to see what arguments it expects.

It seems to me that some core perl functions, such as splice, push, pop, shift and unshift use prototypes because the name of the functions as well as the way they are called read easier in the english language. "Push onto this array the following list" rolls off the tongue better than "Call the push() function with a reference and a list to add to it". push \@array, @list; just doesn't look right. Whenever I see a call to a subroutine with an array as the first argument, I generally assume that a copy of an array is being passed to the subroutine and that each item in the array will fill @_, not that it will all be within $_[0].

It all comes down to a matter of preference, but I'd like to think that more people stick to passing references than creating a prototype for every subroutine they write. I'd be interested in hearing other opinions on this matter. Which method of passing arguments do you use more frequently and why?


In reply to Re ^2: how does splice do it? by Coruscate
in thread how does splice do it? by LanceDeeply

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.