Reputation: 5247
My Perl Script retrieves the argument in the below way. Have Getoptions function to retrieve the command line arguments.
./test.pl -mode report -writeid 12 13 23......
$rc=GetOptions( 'mode=s' => \$cmdParams{mode} ,'writeid:i{1,}' => \@writeid ,'h|?|help' => \$help );
The problem is when i have alphanumeric characters in the writeid option it's not failing. Writeid is defined as integer ( i{1,}) and it can receive 1 to many values. It doesn't fail when i have alphanumeric character in the second value. ./test.pl -mode report -writeid 12 A3 23......
What is the workaround i can do?
Upvotes: 1
Views: 2978
Reputation: 66
As you are using the GetOptions function I assume you are using GetOpts::Long, the trouble with the "{1,}" one or more quantity in the option specification is that once you've successfully matched an integer, you've "succeeded". if you removed the quantitive spec and just ran with 'writeid:i' => \@writeid, each write_id would have to be preceded by the flag on the command line and so you would get an error state when it failed to parse.
Upvotes: 2