in reply to Re: Declaring Subroutines (predeclare, catch errs at compiletime?)
in thread Declaring Subroutines
Unfortunately, you're confused. But it's a mistake that many people make. I myself was confused until I read this useful article on Prototypes in Perl.
Basically, prototypes are not for catching errors at compile time. Rather, they're for changing the precedence of the subroutine calls.
Normally (when not using parentheses or pototypes), subroutine calls act as list operators, meaning the slurp up everything after them. For example:
print my_sub 1, "\n"; # Actually means: print my_sub(1, "\n");
Prototypes allow you to change this behaviour so that the subroutine call only slurps up as many values as it needs (unless, of course, you explicitly use parentheses).
The article does a better job of explaining it but I hope that helps at least some. :-)
bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (bbfu) (prototype misconception) Re(2): Declaring Subroutines (predeclare, catch errs at compiletime?)
by hdp (Beadle) on Apr 25, 2001 at 05:58 UTC | |
by tilly (Archbishop) on Apr 25, 2001 at 17:52 UTC | |
by bbfu (Curate) on Apr 25, 2001 at 06:59 UTC |