in reply to Limit number of Sub routine argument list
Can we strict the subroutine in perl to receive number of arguments ?Runtime? Compile time? Is @a considered to be one argument, or as many arguments as @a has elements?
Runtime is easy:
Compile time, you can do:sub foo { unless (@_ <= 4) { die "foo allows at most 4 arguments"; } ... }
The disadvantage of the latter is that it evaluates all the arguments to the sub in scalar context, and hence there's no flattening of lists. That is,sub foo (;$$$$) { ... }
is not an error - it calls foo with a single argument, 6; the number of elements in @bar.@bar = qw[red blue green yellow brown pink]; foo @bar;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Limit number of Sub routine argument list
by ganeshwari (Sexton) on Oct 25, 2009 at 15:26 UTC | |
by ysth (Canon) on Oct 25, 2009 at 18:43 UTC | |
by JavaFan (Canon) on Oct 25, 2009 at 16:32 UTC |