http://qs321.pair.com?node_id=469464


in reply to -x accepts up to 3 additional arguments

Yeah, the Getopt::Long convention for switches with multiple arguments would be to specify the same switch multiple times on the call, like:

script.pl -x opt1 -x opt2 -x opt3

Since it seems that's not an option, (apologies for the pun) you can still use Getopt::Long, but I think you'll need to do something a little less nice. Maybe like:

my @x; my @y; my $z; GetOptions( #three options required 'x=s' => sub { shift(); push(@x, shift, shift(@ARGV), shift(@ARGV)); + }, #two options required 'y=s' => sub { shift(); push(@y, shift, shift(@ARGV)); }, 'z=s' => \$z) or die ("Invalid arguments");

This reaching into @ARGV has the obvious side effect of potentially breaking further option processing if the number of options isn't exactly what you expect. You could easily add you own logic to the processing functions though. (The initial shift discards the first parameter, which is the option itself (-x, -y, etc))


Xaositect - Whitepages.com