in reply to Subroutine Prototyping/Subroutine Argument Parsing
I am doing this mostly as a means to learn about prototyping, subroutines, and later, making modules.
The absolutely most important thing to learn about Perl's prototypes is that in most cases — almost all cases, really — they should not be used at all. They are not prototypes by any definition that you may be expecting if you came to Perl from another language.
Their primary reason for existing at all is to allow us to write subs that have the same semantics as some builtins. The ability to prototype a sub that takes a BLOCK can be used to extend the language syntax, but that's generally not a good idea anyway. An empty prototype can be a hint that the sub might be inlinable, which is nice and all but usually it's almost meaningless in terms of real performance.
Not only do Perl's prototypes fail to do what you expect, but they fail to do it in ways that can be real easy to trip over. If you haven't already read the link that BrowserUk gave you, read it now. In fact, even if you have already read it, read it again. And avoid prototypes until you really understand the issues involved. You'll be saving yourself headaches in the long run.
Update: Erk! Changed to reflect what I meant... I do not have some absurd prejudice against Perl's subroutines. :-) Thanks BrowserUk!
-sauoq "My two cents aren't worth a dime.";
|
|---|