与getoptions function perl multi value not working类似的问题,我猜......无论如何,似乎只是使用"optlist=s" => \@list,
对我有用,将重复/重复选项存储在数组中;这是我的版本:
$ perl --version | grep This && perl -MGetopt::Long -le'print $Getopt::Long::VERSION;'
This is perl, v5.10.1 (*) built for i686-linux-gnu-thread-multi
2.38
一个例子(test.pl
):
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my $numone = 0;
my $numtwo = 1;
my @list=();
my $result;
$result = GetOptions (
"numone=i" => \$numone,
"numtwo=i" => \$numtwo,
"optlist=s" => \@list,
);
printf("result: %d;\n", $result);
printf("numone: %d, numtwo %d, optlist:\n", $numone, $numtwo);
foreach my $tmplist (@list) {
printf(" entry: '%s'\n", $tmplist);
}
测试输出:
$ perl test.pl --numone 10 --numtwo 20 --optlist testing --optlist more --optlist options
result: 1;
numone: 10, numtwo 20, optlist:
entry: 'testing'
entry: 'more'
entry: 'options'