EvilZone
Programming and Scripting => Scripting Languages => : Satan911 May 11, 2012, 10:00:50 PM
-
Hey,
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=f{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?
-
seems to work for me, maybe it's because f{3} expects a float. although I get a different error message:
Value "op1" invalid for option arg1 (real number expected)
maybe diff versions with different error messages?
~ $ cat test.pl
#!/usr/bin/perl
use Getopt::Long;
GetOptions('arg1=s{3}' => \@a);
print "arg: $_\n" foreach(@a);
~ $ perl test.pl --arg1 op1 op2 op3
arg: op1
arg: op2
arg: op3
~ $ cpan -l 2>/dev/null | grep Getopt
Getopt::Long 2.38
Getopt::Std 1.06
anyway I'd try out that exact code and see if it works, if not idk.
-
Yea I checked the version and I'm also running 2.38 and perl v5. I don't know what the problem but since the feature is still experimental and requires at least 2.35 I probably won't be using it because this is part of a solution for clients and I know damn well most of them don't upgrade most of their servers. Will try to look for an alternative, possible asking the user to separate multiple arguments with , or ;