in reply to -x accepts up to 3 additional arguments

From your description, it sounds like what you want is something closer to

my ( $x_opt, $y_opt, $z_opt ); my $status = GetOptions( x => \$x_opt, y => \$y_opt, z => \$z_opt, ); die $USAGE if !$status || !@ARGV || ( 1 < grep $_, $x_opt, $y_opt, $z_opt ) || ( $x_opt and @ARGV != 4 ) || ( $y_opt and @ARGV != 3 ) || ( $z_opt and @ARGV != 2 );
The last line dies if any one of these conditions holds:
  1. GetOptions failed for some reason (hence $status will be false);
  2. No arguments (@ARGV is empty);
  3. More than one of -x, -y, and -z were specified on the command line (the grep expression will return a list of more than one item in this case);
  4. -x, -y, or -z was specified with the wrong number of arguments.

Updates: Added remarks to explain the last statement. Changed warn $USAGE and exit 1 to the less flexible but simpler die $USAGE.

the lowliest monk

Replies are listed 'Best First'.
Re^2: Getopt::Long making use of $ARGV[n]
by tcf03 (Deacon) on Jun 24, 2005 at 13:00 UTC
    For the sake of not spending too much time on this script, Ill probably go with something like this - and revisit the issue when I have time. Thanks!

    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson