Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line arguments with multiple values

I'm doing a perl script and I need to get multiple values from the command line. Example:

perl script.pl --arg1 op1 op2 op3

I'm using Getopt::Long and I can get this to work:

perl script.pl --arg1 op1 --arg1 op2 --arg1 op3

But I really need (want) the first option.

I checked in their documentation and this is supposed to do what I want:

GetOptions('arg1=s{3}' => \@myArray);

http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pm#Options_with_multiple_values

But I'm getting this error:

Error in option spec: "arg1=f{3}"

Any ideas / solutions?

like image 945
Chris911 Avatar asked Dec 27 '22 01:12

Chris911


1 Answers

Your code works for me, but it looks like that feature was only added to Getopt::Long recently (version 2.35), so you might have an old version of Getopt::Long. Run

perl -MGetopt::Long -le'print $Getopt::Long::VERSION;'

to see what version you have.

like image 158
Robert Young Avatar answered Jan 05 '23 17:01

Robert Young