Which grep is on your mind, the internal perl function grep or the command line utility grep? Generally there is (especially in Perl) more than one way to do things, though some are better than others in a given situation.
You also seemed to imply that both data files are huge. Does that mean you are searching for thousands or millions of values in file 2 ?
If that were the case, a lot would depend on the characteristics of the data. If it is only single words you could create a hash (stored on disc) of the words in file 1 and check every word in file 2 for existance in the hash. If you are looking for whole lines instead, you could sort file 2 and your seach list and work from the beginning in both lists
If the list you are looking for is small on the other hand you could concatenate all search strings with '|' and use that string as search pattern, somewhat like this (untested):
my $searchstring= '\Q' . join('\E|\Q',@output). '\E'; while (my $line=<FILE2>) { if ($line=~/$searchstring/) { print $line; } }
\Q and \E make sure your search strings have any regex special characters like '|' escaped.
Other observations: ++ for your use of warnings and strict. But you also should indent correctly. Makes your code much more readable
And concerning your second posting. Please edit and use code tags for your data examples too
In reply to Re: General program and related problems
by jethro
in thread General program and related problems
by micky744monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |