yonyon100 yonyon100 - 1 year ago 91
Perl Question

Save multiple values of a command line option in Perl array

I have a script that needs to take some options, one of these is -i (input).
I tried the following code to get the input parameters into an array:


use strict;
use warnings;
use Getopt::Long;

my @input = ();
my $help = '';
my $other = '';

'help' => \$help,
'input=s{1,}' => \@input,
'other=s' => \$other

When I try to run it as
./my_script.pl -i param1 param2 -o aaa
I get this:

Error in option spec: "input=s{1,}"

If i run it explicitly with perl as
perl my_script.pl -i param1 param2 -o aaa
everything works smoothly.
Is there a way to get these parameters into an array (not using
) without explicitly invoking perl from the command line?

Answer Source

Turns out I have more than one version of perl installed. One of them (the older one) probably has an older version of the Getopt::Long module that doesn't support the input=s{1,} syntax. When I switched to invoking perl from the most up-to-date version installed, the script ran with no errors.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download