in reply to Re: 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 ?

Hello Athanasius ! Thanks for your answer : i don't want to leave my loop until i know how many users with the password 123456$ i have in the file. Cheers.
  • Comment on Re^2: How to optimize a regex on a large file read line by line ?

Replies are listed 'Best First'.
Re^3: How to optimize a regex on a large file read line by line ?
by Athanasius (Archbishop) on Apr 16, 2016 at 14:26 UTC

    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,