in reply to Open several files and read line by line

One pretty standard way is to just pass the file(s) on the command line and parse each file one after the next:
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); }
Called like:
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

    Thanks for the super fast reply, toolic.

    That worked very well and I don't see the glob issue any more either.

    I thought of and tried a few ways to achieve my purpose, but failed to see the most simple one. Thank you for clearing this up so quickly. I appreciate it!