Which produces something like the following:use strict; use warnings; use Getopt::Long; my @current_params; my $counter; while ( @current_params = get_next_set() ) { $counter++; print "\nloop $counter:"; local @ARGV = @current_params; my ($alpha,$beta,$gamma); GetOptions ( 'Alpha|a' => \$alpha, 'Beta|b' => \$beta, 'Gamma|g' => \$gamma, ); if ( $alpha ) { print "ALPHA FOUND." } if ( $beta ) { print "BETA FOUND." } if ( $gamma ) { print "GAMMA FOUND." } } ######################## sub get_next_set ######################## { my @temp_set; while ( @ARGV ) { push @temp_set,shift @ARGV; last if $temp_set[$#temp_set] !~ /^-/ and defined $ARGV[0] and $ARGV[0] =~ /^-/; } return @temp_set; } ##get_next_set
Anyhow this is the first thing that came to mind when I read your post. And I would like to hear what problems, nuances, I might have overlooked.E:\>232942.pl -a -b FOO BAR -a -b -g BAR FOO -a -g FOO loop 1:ALPHA FOUND.BETA FOUND. loop 2:ALPHA FOUND.BETA FOUND.GAMMA FOUND. loop 3:ALPHA FOUND.GAMMA FOUND. E:\>
-enlil
In reply to Re: How to parse these command-line options?
by Enlil
in thread How to parse these command-line options?
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |