on-internet
← Community

Get an input of array using GetOptions

Stack Overflow ·

I am trying to get create a file in Perl using GetOptions from Getopt::Long, and one of the inputs is an array. My code looks like this: my $filename = 'grid.sh'; my @job_name; my $output_file; my $testbench; my %opts = ( 'job_name' => \@job_name, 'output' => \$output_file, 'testbench' => \$testbench, ); GetOptions( \%opts, 'job_name=s', 'output=s', 'testbench=s' ); open(my $fh, '>', $filename) or die "Could not open"; for (my $i=0; $i <= 2; $i++) { print $fh "Job names are $job_name[$i]"; } close $fh; In my command line I am providing the input as: perl grip_script.pl "-job_name test -job_nam

Comments

Sign in or sign up to comment and upvote.

No comments yet.