Hi,
I am using getopts for argument processing, thus
print_usage if ( ! getopts(':hxarw:l:f:c:e:s:R:v:', \%opts) || exists($opts{h}));in the hope that when configured incorrectly (from an arg perspective), it will print_usage.However when i run my program thus
lock -c test -l test -f locktest -x -r 5getopts does not complain about the -r argument having value 5, nor does getopts complain when i do
lock -c test -l test -f locktest -x 5 -rit simply obeys the : rules and throws that stuff away..:-)
Is there a recommended way to compare actual cmd line args vs what getopts expects?
In the end i wrote a short loop to total up arguments in %opts hash thus
foreach my $arg ( keys %opts ) { log_debug "Argument $arg has value $opts{$arg}"; log_debug "Pre Running total is $getopts_args"; if ( $opts{$arg} eq "1" ) { $getopts_args += 1; } else { $getopts_args+= 2; } log_debug "Post Running total is $getopts_args"; }
which i compare aginst scalar @ARGV if they don't match i carp
Am i insane? Rgds RichardIn reply to getopts and ARGV by rugwuk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |