in reply to How to optimize a regex on a large file read line by line ?
Hello John FENDER, and welcome to the Monastery!
Since you don’t print a result until the loop has finished, it appears that you expect the regex to match only once. In that case, you can cut the time substantially1 by exiting the loop as soon as a match is found:
while (FH) { ++$counter; if (/1234556$) { ++$counter2; last; } }
See perlsyn#Loop-Control.
1By half, on the average, if the matching line appears in a random location within the file.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to optimize a regex on a large file read line by line ?
by John FENDER (Acolyte) on Apr 16, 2016 at 14:15 UTC | |
by Athanasius (Archbishop) on Apr 16, 2016 at 14:26 UTC |