Welcome to the Monastery | |
PerlMonks |
Re: What's the better Perl style? Define parameters or not?by biohisham (Priest) |
on Jan 05, 2010 at 04:36 UTC ( [id://815691]=note: print w/replies, xml ) | Need Help?? |
That depends on the requirements and flexibility you want to impose when working with subroutines,
The different ways you can declare subroutines in Perl are a combination of what you have read in these books, and generally, to brief it:
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: 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... 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... Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
In Section
Seekers of Perl Wisdom
|
|