in reply to Re^2: grepping a large file and stopping on first match to a list
in thread grepping a large file and stopping on first match to a list

[I haven't logged in for a tenday or so. Apolgies for the late response.]

In an earlier post, Anonymous Monk wrote:

"The approach suggested by kcott (compiling the combined regex; not the tie stuff) should be fairly efficient."

I'd just like to say that I concur with the "not the tie stuff" part.

"... to address some of the questions in kcott's reply ..."

Thanks for that. I think you shouldn't use any modules at all (except the pragmata). Consider code like this:

#!/usr/bin/env perl # # pm_1155868_first_grep_large_file_2.pl [no modules] # use strict; use warnings; use autodie; open my $lines_fh, '<', input_filename(); while (<$lines_fh>) { next unless is_a_match($_); process_match($_) and last; } sub input_filename { 'pm_1155868_input.txt' } sub get_strings { [qw{rst uvw xyz}] } BEGIN { my $re = '(?:' . join('|', @{get_strings()}) . ')'; sub is_a_match { $_[0] =~ /$re/ } } sub process_match { print "Match: $_[0]" }

It produces the same output:

$ pm_1155868_first_grep_large_file_2.pl Match: dddddddxyzdddd

— Ken