Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Using Getopt::Long and prompting for arguments

by why_bird (Pilgrim)
on May 01, 2008 at 08:25 UTC ( [id://683881]=note: print w/replies, xml ) Need Help??


in reply to Using Getopt::Long and prompting for arguments

From the CPAN description of GetOpt::Long, for variables which can take a value:

"In the option specification, the option name is followed by an equals sign = and the letter s. The equals sign indicates that this option requires a value. The letter s indicates that this value is an arbitrary string. Other possible value types are i for integer values, and f for floating point values. Using a colon : instead of the equals sign indicates that the option value is optional. In this case, if no suitable value is supplied, string valued options get an empty string '' assigned, while numeric options are set to 0."

So if you set the value to be optional, and if a user does not enter a filename, the value of $user_wants{CUSTOM_SAVE_PLACE} will be ''.

if ((defined $user_wants{CUSTOM_SAVE_PLACE}) && ($user_wants{CUSTOM_SA +VE_PLACE} == '')){ print "Please enter a save location\n"; ..etc. }


edit:added 'if defined'
........
Those are my principles. If you don't like them I have others.
-- Groucho Marx
.......

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-26 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found