|
|
| The stupid question is the question not asked | |
| PerlMonks |
Re^2: multiple substitutionby aaron_baugher (Chaplain) |
| on Aug 25, 2012 at 16:39 UTC ( #989736=note: print w/ replies, xml ) | Need Help?? |
|
I answered a similar question recently with a loop:
So I wondered how that would compare to your solution of combining the searches into a single regex. I thought your way might win for a few words, but surely with a lot of words the complexity of the regex would slow it down, right? Well, so much for that theory. The Perl regex engine continues to amaze me. I gave it a pattern combining 676 strings (all two-letter combinations) with pipes like yours, and it blew the forloop method away (92 times faster). It also beat a regex solution using Regexp::Assemble, but I was using very simple and known search strings, so the hand-made pipe method was safe and simple. With unknown or more complex strings, making it harder to hand-make a safe and efficient search pattern, I think RA would probably come out on top eventually. Anyway, my test and results:
Aaron B.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||