Additional information not provided by Paladin's correct answer:

Perl compiles from the first token in the file to the last token in the file. It does not perform multiple passes. Any information that it has regarding expected syntax needs to have been processed before the compiler reaches the token that uses the syntax.

In order for Perl to recognize a list operator as a subroutine call ("foo;" or "foo 1, 2, 3;"), it must know, at the point that the list operator is used, that a subroutine by that name exists. The only ways for Perl to know this, is if the function was already defined (specified earlier), or if it was predeclared ("sub foo;").

With respect to other answers: It is usually wrong to prefix a subroutine call with '&'. The '&' prefix effectively tells Perl to 'invoke subroutine using Perl 4.x compatibility mode.' (Perl 4.x and earlier required subroutine calls to be prefixed with '&'... it was not optional) The effect is that subroutine calls that use '&' as a prefix do not have prototype processing applied to the argument list. See the perlsub manpage for more information.


In reply to Re: Forward-referenceing subs by MarkM
in thread Forward-referenceing subs by John M. Dlugosz

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.