in reply to Limit number of Sub routine argument list

Maybe like this?  (You didn't say what is supposed to happen if there are more than a certain number of arguments, i.e. ignore, warn, die,... at runtime or compile-time...)

#!/usr/bin/perl sub foo { $#_ = 3 if @_ > 3; # limit to 4 args print "$_\n" for @_; print "---\n"; } foo(1,2,3); foo(1,2,3,4); foo(1,2,3,4,5); __END__ 1 2 3 --- 1 2 3 4 --- 1 2 3 4 ---

(obviously, what I've shown implements the 'ignore' variant)

Replies are listed 'Best First'.
Re^2: Limit number of Sub routine argument list
by Anonymous Monk on Oct 25, 2009 at 09:42 UTC
    Or
    #!/usr/bin/perl -w use strict; use Params::Validate qw' validate_pos '; Main( @ARGV ); exit( 0 ); sub Foo { validate_pos( @_, 1, 1, 1 ); print "$_\n" for @_; print "---\n"; } sub Main { Foo(1,2,3); Foo(1,2,3,4); Foo(1,2,3,4,5); } __END__ 1 2 3 --- 1 2 3 --- 4 parameters were passed to main::Foo but 3 were expected at - line 12 main::Foo(1, 2, 3, 4) called at - line 21 main::Main() called at - line 7