I don’t know how to convince Getopt::Longto do exactly what you ask, but I often use shell quotation to group several elements into one line, and then split the line into an array:
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
my @files;
my $filelist;
GetOptions('file=s' => \$filelist);
if ($filelist) {
$filelist =~ s/^\s+//;
@files = split /\s+/, $filelist;
}
print Dumper(\@files);
__END__
perl multipls.pl --file "filename=a.txt filename=b.txt"
$VAR1 = [
'filename=a.txt',
'filename=b.txt'
];
source
share