Hello PKV,
Welcome to the Monastery. An alternative solution is also the module Getopt::Declare that supports loading arguments into array references as well.
A very nice short example has being given in the forum, read here for more information Getopt::Declare. Minor sample of code bellow:
#!/usr/bin/env perl use strict; use warnings; use Getopt::Declare; # Note the '...' after each tag tells Getopt::Declare to gather argume +nts into an array reference. my $spec = <<'EOS'; -p <INFILE>... input filename(s) [required] { defer{process(@INFILE)} } -f <INFILE>... input filename(s) [required] { defer{process(@INFILE)} } EOS my $opts = Getopt::Declare->new($spec); sub process { @ARGV = @_; while(<>){ chomp; # do something here... } print $ARGV . "\n"; } __END__ $ perl test.pl -p out.txt -f in.txt -p out.txt -f out.txt out.txt in.txt out.txt out.txt
Hope this helps, BR.
In reply to Re: Passing multiple input files to a Perl script through command line
by thanos1983
in thread Passing multiple input files to a Perl script through command line
by PKV
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |