in reply to Re^2: How to optimize a regex on a large file read line by line ?
in thread How to optimize a regex on a large file read line by line ?
Ah yes, I see. In that case, you’re going to have to read through the whole file, and I doubt there’s much you can do to speed up the loop.
BTW, when I saw the regex /123456$/, I assumed you wanted to match 123456 at the end of a line — that’s what the $ anchor means in a regex. If you want to match a literal $, you need to escape it: m{123456\$} or:
use strict; use warnings; use autodie; ... my $password = '123456'; open(FH, '<', "../Tests/10-million-combos.txt"); $counter = 0; $counter2 = 0; while (<FH>) { ++$counter; ++$counter2 if /^Q$password/; } print "Num. Line : $counter - Occ : $counter2\n"; close FH;
See quotemeta.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|