Saving multiple command line parameter values ​​in a Perl array

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

#!/usr/bin/perl

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

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

GetOptions(
    '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 the following:

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

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

+4
source share
1 answer

, ​​ perl. ( ), , Getopt:: Long, input=s{1,}. perl , script .

+2

Source: https://habr.com/ru/post/1650537/


All Articles