In general, the consensus is that Perl 5's simple subroutine syntax is just a little too simple. Well, okay, it's a lot too simple. While it's extremely orthogonal to always pass all arguments as a single variadic array, that mechanism does not always map well onto the problem space.

-- Larry Wall in Apocalypse 6 (2003)

Yes, I see your point, so let me clarify. Minimizing variable scope is a sound general programming practice that I strive to employ in all languages I currently use (C++, Perl, Python, Ruby, Java). That is my strategic goal. This "unpack subroutine arguments at the top of the sub" business is just a pragmatic tactic used to work around Perl 5's primitive subroutine syntax. That is, in most languages, the scope of function arguments is the whole function and that is made plain by the language syntax. Explicitly unpacking Perl's appallingly non-descriptive $_[0], $_[1], ... subroutine argument names at the top of the subroutine to more meaningful lexically scoped names is usually the clearest way to express that these are indeed the function's arguments and that their scope is accordingly the whole function. In the common case of read-only subroutine arguments, it is also safer in that it avoids accidentally changing the passed arguments. The reasons behind this rule are described in detail in Perl Best Practices, along with exceptions to this rule (e.g. short and simple subs, when efficiency is critical, ...).


In reply to Re^3: How do I prototype a function with a varying number of arguments? by eyepopslikeamosquito
in thread How do I prototype a function with a varying number of arguments? by lyapunov

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.