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 5

getopts 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 -r

it 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 Richard

In reply to getopts and ARGV by rugwuk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.