in reply to how to parse large files
You are reading a new line from the log file each time you try a match in the "if" statement. Make thatwhile (<$fh>) { foreach my $subset (keys %lookingFor) { foreach my $item (@{$subset}) { if (<$fh> =~ m/$item/) { my $writeFh = new FileHandle ">> myout.log"; print $writeFh <$fh>; } } }
so you run all the matches on the current line. That won't make it faster but correcter.if ( m/$item/ ) {
Further, you are re-opening the output file each time there is something to write. Open it once before the loop (simple write mode is okay, no need for append), and just use it in the loop. That will make it faster though there's no way of saying by how much.
Try that. If it's still too slow, go back to optimizing the regex work.
Anno
|
|---|