GetOptions
will leave any arguments that it didn't parse, in the @ARGV
variable. So you can just loop over the @ARGV
variable.
use Getopt::Long;
my %opt;
GetOptions(
\%opt,
'mode=s'
);
for my $filename (@ARGV){
parse( $filename, \%opt );
}
There is another option, you can use the special <>
argument callback option.
use Getopt::Long qw'permute';
our %opt;
GetOptions(
\%opt,
'mode=s',
'<>' => sub{
my($filename) = @_;
parse( $filename, \%opt );
}
);
This is useful if you want to be able to work on multiple files, but use different options for some of them.
perl test.pl -mode s file1 file2 -mode t file3
This example will set $opt{mode}
to s
, then it will call parse
with file1
as an argument. Then it will call parse
with file2
as the argument. It will then change $opt{mode}
to t
, and call parse
with file3
, as an argument.