in reply to How to efficiently search for list of strings in multiple files?
But it is not clear whether you can easily get rid of these nested loops.while (my $line=<$txtfile>) { foreach (@InputData_Unions)
One typical way to get rid of nested loops is to store keywords in a hash and have a hash lookup instead of a sequential list search, but that doesn't quite work here (at least not easily) with your Unions list containing several words.
Depending on how large your list of unions is, you could possibly build a regex with alternates for each union, something like:
With the data you've shown, I would start by excluding any line that doesn't contain the word "Sarnia":if ($line =~/Sarnia Police Association|Sarnia Professional Fire Fighte +rs|.../) { # ...
This would probably make your program very significantly faster, but it may be that looking for "Sarnia" is not really applicable to your real case.while (my $line = <$txtfile>) { next unless $line =~/Sarnia/; foreach (@InputData_Unions) { # ...
My point, though, is that the more you know about your data, the more you're likely to find some improvements or shortcuts.
|
|---|