I check for required flags like this:
It seems to me what you're trying to do is handled much more clearly by assigning a variable based on a flag, then checking that variable's value.my @args; GetOptions ( 'h|help' => sub { $help ++ }, 'debug' => sub { $debug ++ }, 'c|confirm' => \$confirm, 'i|instance=s' => \$instance, 's|service=s' => \@services, 'o|operation=s' => \$operation, 'm|message=s' => \$message, 't|timeout=i' => \$timeout, 'u|owner=s' => \$owner, '<>' => sub { push (@args, @_) } ); pod2usage ( -verbose => $help ) if $help; pod2usage ( -verbose => 1 ) unless scalar @services; pod2usage ( -verbose => 1 ) unless $operation and $message and $owner;
I find Pod::Usage http://perldoc.perl.org/Pod/Usage.html invaluable. And I always use Getopt::Long.
In reply to Re: How to use getopt and $#argv together?
by mpeever
in thread How to use getopt and $#argv together?
by iphone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |