Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Getopt::Long and default number

by jimbojones (Friar)
on Jul 19, 2005 at 18:41 UTC ( #476222=note: print w/ replies, xml ) Need Help??

in reply to Getopt::Long and default number


I think you want the ":" signifier when identifying your options. This says the value for the option is optional. If the option is present without a value, it takes the number indicatied after the ":" ; otherwise it takes the user-supplied value. This is in the POD in the section "Summary of Option Specifications"

use Getopt::Long; my $opt = 0; GetOptions ("opt:100" => \$opt ); print "Opt is:\t$opt\n";
My test runs give:
> --opt Opt is: 100 > --opt 7 Opt is: 7 > Opt is: 0

- j

Comment on Re: Getopt::Long and default number
Select or Download Code
Replies are listed 'Best First'.
Re^2: Getopt::Long and default number
by mrborisguy (Hermit) on Jul 19, 2005 at 19:06 UTC

    Bingo! Thanks! ++


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2016-02-05 23:46 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (210 votes), past polls