You should note that your proposed solution (using Perl in a C-like fashion with a main() function) does not actually aid the compiler in any way.

The compiler compiles all tokens in sequence from the first to the last. Certain constructs, such as 'BEGIN{...}' or 'use ...;' are executed as soon as they finish compiling, and cause the compiler to recurse, while other constructs such as "sub NAME ..." generate symbol table entries as soon as they finish compiling.

Your code defines the symbol 'main' (perhaps confusing, given that the fully qualified name is 'main::main'), uses the symbols 'get_input' and 'say_hello'. Then defines the symbol 'get_input' and 'say_hello'. At the very end, the compiler terminates and the execution phase begins. The first executable statement is 'main()'.

Definately, choosing to always invoke subroutines using () over using list operator syntax, will avoid this particular problem. The problem that it does not avoid, is the situation where a subroutine is invoked, but later prototyped:

a(@a); sub a ( \@ ) { my($array_reference) = @_; }

If -w is not used, Perl is perfectly happy to execute the above code generating undesirable results ($array_reference is assigned the first value in @a). If -w is specified, Perl generates the warning message:

main::a() called too early to check prototype at ...

Moral of the story: If you use prototypes at all, make sure to always pre-declare your subroutines using "sub NAME (PROTOTYPE);". However, if you have read about the pitfalls regarding prototypes, you may decide that it is reasonable to completely avoid using prototypes at all, in which case, always using () when invoking subroutines will eliminate the problem described by the original poster (list operator not recognized).

Secondary moral of the story: -w can be extremely useful.


In reply to Re: 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.