Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Open several files and read line by line

by toolic (Bishop)
on Dec 04, 2015 at 15:21 UTC ( [id://1149393]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1149393]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found