Click here to get back home

Getopt::Std question

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Getopt::Std question sstark 09-07-2005
Posted by sstark on September 7, 2005, 9:42 am
Please log in for more thread options


When using Getopt::Std, if I use:

getopts('c:');

....and the user specifies the -c flag but fails to specify a parameter
for the flag, such as:

> myscript -c

....how do I detect an error? The -c flag is optional but the parameter
is required if used.

If I just say:

if !($opt_c){
# this is the same as not using -c at all...
}

thanks,
Scott



Posted by Jim Gibson on September 7, 2005, 10:27 am
Please log in for more thread options



> When using Getopt::Std, if I use:
>
> getopts('c:');
>
> ...and the user specifies the -c flag but fails to specify a parameter
> for the flag, such as:
>
> > myscript -c
>
> ...how do I detect an error? The -c flag is optional but the parameter
> is required if used.
>
> If I just say:
>
> if !($opt_c){
> # this is the same as not using -c at all...
> }

Check the return value of getopts. It will be true (1) if no error
occurred, and false (undef) if there was some error, such as a missing
parameter for an option that needs one.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com


Posted by sstark on September 8, 2005, 9:32 am
Please log in for more thread options


thanks Jim!



Similar ThreadsPosted
Is this bug in Getopt::Std? October 20, 2006, 3:00 pm
Getopt::Simple V 1.47 July 29, 2004, 7:18 am
[Fwd: Re: What happened to Getopt::Std ?] June 13, 2007, 6:34 am
Version? of getopt::Long October 4, 2004, 2:48 pm
Announce: Getopt::Simple V 1.48 November 16, 2004, 10:29 am
Getopt::Long install problems October 4, 2004, 6:33 pm
Parsing function args in Getopt::Long style January 11, 2008, 4:11 pm
DBI question November 5, 2004, 4:28 pm
Newbie Question January 3, 2005, 4:11 pm
LWP question on windows98 October 7, 2004, 8:19 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap