kprice++ has asked for the wisdom of the Perl Monks concerning the following question:
So, first off, this is for a homework assignment. The problem involves taking an arbitrarily long list of REGEX strings and searching for them in a file. Would it be better, or faster, to search each line in the file, one string at a time or with alternation...(str1|str2).
my $rexs = '(' . join('|', @regexs) . ')'; #... if(/$rexs/) {...} #or.. foreach $rex (@regexs) { if(/$rex/) {...} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Alternation vs. looping for multiple searches.
by roboticus (Chancellor) on Nov 21, 2010 at 03:16 UTC | |
by kprice++ (Novice) on Nov 21, 2010 at 06:03 UTC | |
|
Re: Alternation vs. looping for multiple searches.
by PeterPeiGuo (Hermit) on Nov 21, 2010 at 02:21 UTC | |
by kprice++ (Novice) on Nov 21, 2010 at 06:04 UTC | |
|
Re: Alternation vs. looping for multiple searches.
by JavaFan (Canon) on Nov 21, 2010 at 14:54 UTC | |
|
Re: Alternation vs. looping for multiple searches.
by chrestomanci (Priest) on Nov 21, 2010 at 13:49 UTC | |
by JavaFan (Canon) on Nov 21, 2010 at 14:44 UTC | |
|
Re: Alternation vs. looping for multiple searches.
by aquarium (Curate) on Nov 21, 2010 at 22:15 UTC |