Getopt::Std question
am 07.09.2005 18:42:32 von sstark
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
Re: Getopt::Std question
am 07.09.2005 19:27:01 von Jim Gibson
In article <1126111352.512126.287460@g49g2000cwa.googlegroups.com>,
sstark wrote:
> 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