How many strings are you searching for? Is it just 2 or 3, or is it 200-300?
Can the match span lines in the big file? Like this, for instance:
That would obviously complicate things..................AAAAAAAA"ATGGCTC GTGTCCA"AAAAAAAAAAA ...........
If you only have a manageable number of strings to match, and a match can't occur across lines, I'd suggest something like this (which does use regexes, but if you have multiple strings to match at once, I don't know how to avoid them easily):
I haven't tested this, but it could be a start for you...use Regex::PreSuf; sub superMatch { my ($patternFile, $dataFile, $outFile)=@_; open(PAT,"<$patternFile") or die "Can't open $patternFile, error $ +!"; my @patterns=<PAT>; chomp @patterns; close(PAT); open(OUT, ">>$outFile") or die "Can't open output file $outFile, e +rror $!"; # Regex::PreSuf generates a regex that will match all # of the patterns much more quickly than a naive # join "|",@patterns will my $re=presuf(@patterns); open(DATA,"<$dataFile") or die "Can't open $dataFile, error $!"; # NO NEED TO READ INTO MEMORY ALL AT ONCE! while(<DATA>) { # only compile regex once if(/$re/o) { # only chomp if we have a match chomp; # capturing matches are slower, so only capture # if one or more matches are present. # might have more than one match in a line! while(/($re)/og) { print OUT "'$1', '$_'"; } } } }
In reply to Re: Quickest method for matching
by RMGir
in thread Quickest method for matching
by dr_jgbn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |