in reply to Open several files and read line by line
Called like:use strict; use warnings; use Getopt::Long; GetOptions( 'id1=s' => \my $id1, 'id2=s' => \my $id2, ); for my $file (@ARGV) { open (my $filename, "<", $file) or die "Could not open $file, $!"; while (<$filename>){ while (/$id1/g && /$id2/g) { print "$file:$.\n"; } } close ($filename); }
script.pl --id1="test1|test2" --id2="test3|test4" file1.txt file2.txt
Regarding your glob problem, post a small sample of your input file so others can reproduce the issue.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Open several files and read line by line
by Leiria (Novice) on Dec 04, 2015 at 15:36 UTC |