husker has asked for the wisdom of the Perl Monks concerning the following question:
so you can see that I am using the "l:" spec to Getopts to show a required argument. When the user doesn't present an argument after -l, however, I don't see how to detect that condition (apart from another condition that might cause the Getopts call to raise an error). $Options{l} doesn't seem to get set in this case, so I can't determine for myself that "yeah they did a -l, but did no argument", and Getopts itself doesn't issue any error messages about forgetting a required argument. When the user forgets the -l argument, I'd like to tell them that they forgot it, but I don't see how I can tell without going ahead and parsing @ARGV myself .. and if I do that, why even use Getopts in the first place? Any suggestions?$opts = getopts ('uhal:',\%Options); if ($opts) { $print_users = $Options{u}; $print_all = $Options{a}; if ($Options{l}) { $logfile=$Options{l}; } else { $logfile="$IDEAS_DIR/sec/logs/daemon.$HOSTNAME"; } if ($Options{h}) { ShowUsage(); } } else { ShowUsage() ; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getopts and required args
by Shendal (Hermit) on Jun 22, 2000 at 20:10 UTC | |
by husker (Chaplain) on Jun 22, 2000 at 20:34 UTC | |
by Shendal (Hermit) on Jun 22, 2000 at 21:26 UTC | |
|
Re: Getopts and required args
by takshaka (Friar) on Jun 23, 2000 at 07:04 UTC | |
by Anonymous Monk on Jun 23, 2000 at 20:20 UTC | |
by husker (Chaplain) on Jun 23, 2000 at 20:26 UTC |