Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: GetOptions and help

by pboin (Deacon)
on Mar 16, 2006 at 12:48 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found