On Thu, Jun 17, 2010 at 6:50 AM, Shawn H Corey <shawnhco...@gmail.com>wrote:

> On 10-06-17 02:36 AM, Unknown User wrote:
>
>> I have the following code:
>>
>> GetOptions(
>>        "n|name=s" =>   \$name,
>>        "a|age=i" =>  \$age,
>>        "s|sex=s" =>  \$sex,
>> ) || die "Bad options\n";;
>>
>
> But they are complete.  'name' is placed in $name, '-a' is placed in $sex,
> and @ARGV is left with ( '20' ).
>

Technically, -s does have a value: -a. GetOptions is treating "-a" as the
value for "-s" because the string "-a" immediately follows the option -s.
You could add validation on the value of "-s". For example...

GetOptions(
       "n|name=s" =>   \$name,
       "a|age=i" =>  \$age,
       "s|sex=s" =>  \$sex,
) || die "Bad options\n";;

if ($sex !~ m/m(ale)?|f(emale)?/i) { die "Invalid gender $sex\n"; }

-- 
Robert Wohlfarth

Reply via email to