![]() |
|
XP is just a number | |
PerlMonks |
Re^2: Gratuitous use of Perl Prototypesby leriksen (Curate) |
on Nov 09, 2004 at 00:56 UTC ( #406244=note: print w/replies, xml ) | Need Help?? |
If you need particular types in your parameters, another way to achieve this (and quite possibly more robust than prototype as the clinical dissection above shows) is to use the "program by contract" paradigm.
So if you need the first parameter to be an array ref, put in code to test this precondition -
Even better, use Params::Validate If your emulating a builtin like push, using the same interface has advantages (in this case positional parameters), but I prefer using named parameters as much as possible - it also can cut out a number of errors if you choose appropriate parameter names e.g.
Your POD for this sub (dont give me that puzzled look !!!) should document what keys are expected, and the code checks you have keep your part of the contract. use brain;
In Section
Meditations
|
|