From Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen, under the heading “Problems with Regular Prototypes”:
Since we’re having so much fun, let’s move on to “%”. This “prototype” means what? That we’re expecting a hash? Not at all! In fact, it is completely identical to a “prototype” of just “@”. Everything I said about “@” is true for “%”, because they are the same! You can’t get any type checking here. It doesn’t even bother to check whether you have an even number of arguments.
Not official documentation, exactly, but — well, the author did co-write the Camel Book ;-)
Hope that helps,
| [reply] |
> Hope that helps,
thanks, it does, though it was what I expected it helps to know the official truth...
> It doesn't even bother to check whether you have an even number of arguments.
which is - mildly expressed - "unfortunate". I will add a manual check.
| [reply] |
... an even number of arguments...
I will add a manual check.
What are you doing with the arguments subsumed under the % prototype? Well, right now you're probably just writing test code to check the behavior of the prototype, but in a 'real world' case, would you not assign these arguments to a hash? What else? If assigning an odd number of elements to a hash, Perl warns (if warnings are enabled) with no separate check necessary. Granted, the warning doesn't stem from the prototype checking system, but...
>perl -wMstrict -le
"sub H (&%) { my ($cr, %h) = @_; $cr->(%h); }
;;
H { print @_; } qw(a 1 b);
"
Odd number of elements in hash assignment at -e line 1.
Use of uninitialized value $_[3] in print at -e line 1.
a1b
| [reply] [d/l] [select] |
| [reply] [d/l] |