in reply to Re^4: Dictionary filter regex
in thread Dictionary filter regex

I have different results. With a words.txt file containing about 113,800 words, these are my timings. With an array:
$ time perl -e 'open my $fh, "<", "words.txt" or die; my @w = <$fh>; > my $c; > foreach $line(@w) { > if ($line =~ /s.*h/i) { > if ( ($line =~ /s.*s/i) || ($line =~ /h.*h/i) ) { > next; > } > $c++; > } > } > print "$c \n"; > ' 2834 real 0m0.138s user 0m0.093s sys 0m0.016s
Reading directly from the file:
$ time perl -e 'open my $fh, "<", "words.txt" or die; > my $c; > foreach $line(<$fh>) { > if ($line =~ /s.*h/i) { > if ( ($line =~ /s.*s/i) || ($line =~ /h.*h/i) ) { > next; > } > $c++; > } > } > print "$c \n"; > ' 2834 real 0m0.120s user 0m0.093s sys 0m0.015s
I have used exactly the same code except for the use of the array, so that the comparison should be relatively significant.

But the main point is that if the input file gets huge, then you sometimes simply can't load it into an array, because you'll run out of memory.