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

Ah, so it's the loading of the entire file that's slowing me down.
That, and probably smartmatch too (depending on what it does...).
And you say that your and kcott's solutions don't avoid that
No. Just don't use smartmatch and first:
use strict; use warnings; my @strings = qw( foobarbaz111222333444 barbazfoo111555666999 bazfoobar999888777666 ); my $text = <<'END'; bdfjadslfjhasdjklfhjklashdflkjadshfjkladhfjkldhfljkafjadfdji adlfjhdlsjkfuiowerfhwehrbeblbflasdfbhjkaldhqpqheuihfbdfkhyyy qjdpdbnfdbjdfklbasjfbajksdbfjaksdbfjaksdfbjkasdfhydsfadfjyyy END $text x= 1_000_000; $text .= "bazfoobar999888777666\n"; printf "text size: %d bytes (%.2f mb)\n", length($text), length($text) / ( 1024 * 1024 ); my $regex = join '|', map quotemeta, @strings; $regex = qr/^($regex)$/m; printf "found %s at %d\n", $1, $-[0] if $text =~ $regex;
That simulates your memory mapped file.