...
The problem arises from two issues. First, Perl constructs a single argument list from its arguments, and this process includes flattening any arguments that are themselves lists. This is why For this reason, 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).
...
Tool | Diagnostic |
---|---|
Perl::Critic | Subroutines::ProhibitSubroutinePrototypes |
Bibliography
[Conway 05] | pg. 194 "Prototypes" |
[CPAN] | Elliot Shank, Perl-Critic-1.116 Subroutines::ProhibitSubroutinePrototypes |
[Wall 2011] | perlsub |
...