in reply to Forward-referenceing subs
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Forward-referenceing subs
by Aristotle (Chancellor) on Jan 12, 2003 at 16:51 UTC |