...
Prototypes do not cause Perl to emit any warnings if a subroutine's invocation uses methods that don't match its prototype, not even if the -w
switch is used. They also can change function behavior , and consequently should not be used.
...
This noncompliant code example demonstrates a function with prototypes. The function takes a string and a list and simply prints out the string , along with the list elements.
...
The problem arises from two issues. First, Perl constructs a single argument list from its arguments, and this includes flattening any arguments that are themselves lists. This is why Perl allows function()
to be invoked with one list argument , rather than two. Second, the function prototype imposes contexts on the arguments it gets: a single scalar context for the first variable , and a list context from the second variable. These contexts are invoked on the arguments actually provided , rather than on the argument list. In this case, the scalar context is applied to the @elements
list, which yields 3, the number of elements in the list. Then the list context is applied to no argument, since only one argument was specified, and it produces an empty list (with 0 elements).
...
Subroutine prototypes do not provide compile-time type safety , and can cause surprising program behavior.
...