2

Have the below getoptions function. iifiles argument is optional and it can be 1 to many if provided. But when i run this function getting an error message "Error in option spec". Perl running on solaris 10. Not sure what multiple values option for iiles needs to be provided.

GetOptions( 'reportdate=s' => \$cmdParams{repDate}
                   ,'switch=s' =>\$cmdParams{swi}
                   ,'iiles:s{,}' => \@inputFileArray
                   ,'h|?|help'  => \$help
                   );
Arav
  • 4,957
  • 23
  • 77
  • 123
  • Judging from the answers, you might need to run `perl -MGetopt::Std -e 'print "$Getopt::Std::VERSION\n"'` and compare that with the current versions. You can probably find the old documentation on CPAN, but `perldoc Getopt::Std` should also work. – Jonathan Leffler May 07 '13 at 04:16

2 Answers2

3

It looks like your Getopt::Long version does not support repeat specifiers. You can update it, or use a comma separated list for example:

GetOptions('iiles:s' => \$fileList);
@inputFileArray = split(/,/, $fileList);

alternatively, use the rest of the arguments in @ARGV for the list after parsing:

GetOptions('somethings=i'=>\$some);
@inputFileArray = @ARGV;
perreal
  • 94,503
  • 21
  • 155
  • 181
  • Thanks a lot for the info and workaround. Not sure why this option is not work because getoptions is a core module. – Arav May 07 '13 at 04:21
  • @Arav, your core module version depends on the Perl version you are using. – perreal May 07 '13 at 04:29
  • Thanks a lot for the info. am checking the return value from the GetOptions in the below way. Is it the right way to do the check. $rc=GetOptions(....) ; if((!defined($rc)) || ($rc eq "")) { print "Invalid Arguments passed to the script" ; } – Arav May 07 '13 at 06:31
2

Perl running on solaris 10. Not sure what multiple values option for iiles needs to be provided.

There's your problem. What version of Perl are you running? Last time I checked, the standard version of Perl on Solaris was 5.8.4. It might be up to 5.8.9 now. The problem is that the feature you want, specifying the option as 'iiles:s{,}' => \@inputFileArray, probably isn't there in your version of Getopt::Long.

Run this command:

 $ perldoc Getopt::Long

And look for the string coordinates=f{2}. If you can't find it, you don't have that option.

You can live without it. (There are still ways to specify multiple values), or you can try the Sun Freeware Site and see if they have a later version of Perl, or you can download the latest version of Getopt::Long from CPAN. However, be careful to make sure that the version you download works with your version of Perl. I've recently noticed that some of the newer modules require features that are found in Perl post 5.10.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Thanks a lot for the detail. Check the perldoc the line coordinates=f{2} exists but version under it listed as 5.8.8. Checked the perl version which i am running it says 5.8.4. As u said it's a solaris version issue. I am checking the return value from the GetOptions in the below way. Is it the right way to do the check. $rc=GetOptions(....) ; if((!defined($rc)) || ($rc eq "")) { print "Invalid Arguments passed to the script" ; } – Arav May 07 '13 at 06:30
  • @Arav I just do `GetOptions(...) or die qq(Invalid Arguments);`. Actually, I use the [Pod::Usage](http://perldoc.perl.org/Pod/Usage.html) module and its `pod2usage` function instead of `die`. If you don't know what POD is, checkout [perlpod](http://perldoc.perl.org/perlpod.html). – David W. May 07 '13 at 11:58