in reply to Re^6: Prototype for constant items???
in thread Prototype for constant items???
The problem there, is that you are still using prototypes. I am saying; ditch that, and just check the parameters in the sub.
If the caller wants to pass an array as the first parameter, they can throw a reference slash in front of it, or square brackets around it. If they want to pass a list of multiple parameters, they can just pop the ($alpha,@rgb) in there without your sub forcing it into just two parameters and then trying to untangle it later.
My main point: Use prototypes if you want to mangle the caller's code. Use if croak, warn, etc if you want to do type and sanity checking.
Note: If they pass an array where they should have passed an arrayRef, then you should croak with a detailed version of "Too Many Parameters!" and/or "Value out of range", where applicable.
Come to think of it, it would be nice to have a template of:
since that would print out all of the errors before stopping, rather than just one error per run.sub foo { my $failed; ($failed = 1 and carp "First Parameter must be greater than zero") i +f $_[0] <= 0; ($failed = 1 and carp "Too many parameters") if scalar @_ > 3; die "Invalid parameters; cannot continue" if $failed; ... }
|
|---|