hangon has asked for the wisdom of the Perl Monks concerning the following question:
Before this digresses into a tangental discussion - I rarely use prototypes, and yes I do know why I want to use one in this case.
I prefer to place subroutines at the bottom of my programs, which creates a problem with using a prototyped sub. The obvious answer (to me) is to use a BEGIN block, but this doesn't work:
use strict; use warnings; foo('bar'); BEGIN{ sub foo ($){ print "foo called: @_\n"; } } # gives warning message: # main::foo() called too early to check prototype ...
While the following does the job, and I'm ok with it, I'm curious as to why the BEGIN block doesn't work. Can anyone provide some enlightenment?
use strict; use warnings; sub foo ($); foo('bar'); sub foo ($){ print "foo called: @_\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: BEGIN block and prototyped subroutines
by JavaFan (Canon) on Apr 16, 2010 at 17:02 UTC | |
|
Re: BEGIN block and prototyped subroutines
by moritz (Cardinal) on Apr 16, 2010 at 17:02 UTC | |
|
Re: BEGIN block and prototyped subroutines
by cdarke (Prior) on Apr 17, 2010 at 15:36 UTC | |
by hangon (Deacon) on Apr 18, 2010 at 08:12 UTC | |
|
Re: BEGIN block and prototyped subroutines
by ikegami (Patriarch) on Apr 18, 2010 at 08:30 UTC |