A similar question , the getoptions perl multi value function does not work , I think ... In any case, it seems that just using "optlist=s" => \@list,
works for me to save a duplicate / repeat in an array; this is my version:
$ 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
Example ( 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); }
Test output:
$ 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'
sdaau source share