If I had to guess (and I am) it's because your error is being reported during parsing and sub foo {} hasn't been seen yet. So when foo; is encountered the parser has to make a guess at what sort of thing 'foo' is and you just didn't provide enough information.

Additions: Ok, now that it's tomorrow and I've had some sleep I'll add more to this short comment. Actually... reading the source comments is probably a better description than I can provide so I'll copy a bit from my 5.6.1 source. This is from the intuit_method() function which is at least one place where the compiler makes it's guesses as to what is a subroutine or not. Of course, reading these descriptions it quickly becomes apparent that this

S_intuit_method Does all the checking to disambiguate foo bar between foo(bar) and bar->foo. Returns 0 if not a method, otherwise FUNCMETH (bar->foo(args)) or METHOD (bar->foo args). First argument is the stuff after the first token, e.g. "bar".

But then I gather that intuit_method is only called for some of the potential method DWIMery. Further reading shows that it just gets uglier and uglier. What I quoted was probably the most straightforward portion.


Fun Fun Fun in the Fluffy Chair


In reply to Re: Forward-referenceing subs by diotalevi
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.