in reply to What's the better Perl style? Define parameters or not?
As the term "prototype" suggests, you can tell Perl of the type and number of arguments you wanna pass to this subroutine and whether any of these types can be optional, therefore, it is a mechanism to make sure that you don't pass an array to a subroutine when it expects a scalar...
This subroutine above is called with a scalar, list and followed by an optional hash... You can call a subroutine in a number of ways too, but for simplicity I'd only mention two ways:sub SUBNAME($@;\%)
How does this come in context with declaring prototypes?... using the & form of calling a subroutine would deactivate prototype checking that means, as long as you don't preface the subroutine names with & the prototypes provided in the declaration would affect/interfere with the calls to the subroutine...&SUBNAME # & dereferencer is implicit and can be dropped at times. #OR... SUBNAME()
NOTE: I learnt this from The Perl Black Book...
Update: ikegami and BrowserUk, I am happy to have erred and I am happy to have been guided, I was under the impression that prototypes could help validating a subroutine passed arguments, and just verifying this I did not get a proof of concept that such a behavior exists but this left me confused on what I read reviewing the lessons and with a question of "why use them prototypes after all if they are not good at checking functions or are ignored upon such validation?" , I really hope I am not being a dumb now...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What's the better Perl style? Define parameters or not?
by BrowserUk (Patriarch) on Jan 05, 2010 at 05:00 UTC | |
|
Re^2: What's the better Perl style? Define parameters or not?
by ikegami (Patriarch) on Jan 05, 2010 at 05:54 UTC | |
|
Re^2: What's the better Perl style? Define parameters or not?
by cdarke (Prior) on Jan 05, 2010 at 11:53 UTC |