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() ; }
In reply to Getopts and required args by husker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |