in reply to How do I prototype a function with a varying number of arguments?
Why do you want to use prototypes? They almost never do just what you want and/or expect. In any event, optional parameter values must be handled in the same way: by checking in the function that a defined (or otherwise valid) value has been passed.
>perl -wMstrict -le "sub opt_w_proto ($;$) { my ($x, $y) = @_; $y //= 42; print qq{x $x y $y}; } ;; sub opt { my ($x, $y) = @_; $y //= 42; print qq{x $x y $y}; } ;; opt_w_proto(7); opt_w_proto(7,0); ;; opt(7); opt(7,0); " x 7 y 42 x 7 y 0 x 7 y 42 x 7 y 0
|
|---|