in reply to Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???
because perl compiles this patern again & again in the foreach loop.my $regex = qr /(?:$regexstr)/;
If you use this patternforeach my $stringlength (100,1000,10000,100000)
instead ofmy $regex = qr /(?:$regexstr)/o;
It will be fast. Since it compiles the pattern only once.my $regex = qr /(?:$regexstr)/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???
by Roy Johnson (Monsignor) on Feb 18, 2005 at 13:14 UTC |