Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: GetOptions and help

by pboin (Deacon)
on Mar 16, 2006 at 12:48 UTC ( #537108=note: print w/replies, xml ) Need Help??

in reply to GetOptions and help

Try just testing the number of incoming parms, which is in @ARGV..

if ( @ARGV == 0 || $help ) { usage(); exit(1); }

Replies are listed 'Best First'.
Re^2: GetOptions and help
by Anonymous Monk on Mar 16, 2006 at 13:01 UTC
    I had previously tried doing this but it seems that in my case @ARGV is always -1 regardless of the number of arguments.
    Hence if I do this
    $numargs = $#ARGV +1; if ($numargs == 0) { usage(); exit(1) }
    The usage always kicks in regardless of any options that may have been used

      GetOptions is destructive: it consumes @ARGV as it processes. You would need to test @ARGV before calling GetOptions.

      I would suggest this instead, though: Just determine what the required arguments are, and test them. In your case, it seems like the required arguments are an alternation:

      unless ( $alt1 or $alt2 or ( $alt3 and $alt4 )) { usage(); exit; }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://537108]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2021-08-05 02:40 GMT
Find Nodes?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)

    Results (44 votes). Check out past polls.