http://www.perlmonks.org?node_id=154177


in reply to Placement of Subs

On a side note...

If you use prototypes and the sub appears on the bottom (or after the invocation), the prototype will not work as intended. You'll get a "main::subroutine called too early to check prototype" warning and the prototype will not/cannot be checked. When using prototypes, you'll need to either place the sub before its invocation or declare the sub and its prototype:

sub prototest($); # declare sub and prototype prototest( 4 ); # dies if no param or more than 1 param is passed sub prototest($){ print '1, 2, 3, ', @_; }
-or-
sub prototest($){ print '1, 2, 3, ', @_; } prototest( 4 ); # dies if no param or more than 1 param is passed