LPM: getopts *elp
Frank Price
fprice at mis.net
Tue Aug 15 17:15:55 CDT 2000
Hi LexPM,
I'm trying to use Getopt::Std and it isn't working as I'd like.
Thought I'd post here before digging deeper :-)
I want to use an option, -s, which takes an optional argument. If the
argument is given, I want to use that argument. If just the option is
given, I want to use a default value. If the option isn't given, I
don't want to use any value at all. For example, you could say '-s
100', '-s', or omit it entirely.
Here's what I thought would work. It doesn't though: if I don't
specify the argument, $opt{'s'} is set to zero.
use Getopt::Std;
getopts('s:', \%opt);
my $sleep = 0;
if ($opt{'s'}) {
print "opt_s = $opt{'s'}\n";
$sleep = ($opt{'s'} == 1) ? 3600 : $opt{'s'};
}
print "sleep = $sleep\n";
I think Getopt::Long will really do optional numeric args like I want
-- anyone know if I can do this with Std options?
Thanks,
-Frank.
--
Frank Price | fprice at mis.net | www.sxse.org/fprice/
GPG key: www.sxse.org/fprice/gpg.asc | E Pluribus Unix
More information about the Lexington-pm
mailing list