Your second proposal is not very like your first. The results will differ.
The first will probably benefit from study $i; before the inner loop. With 140 matches to try, it is likely to pay off ( but Benchmark).
Consider these questions. Do you want all matches, or just the first match? That means the order of regexen matters. Do you need to retain any information about which regex matched a given @array element? That would be the case if this is a parser of some kind. Do you need to maintain the sequence of @array elements?
Devise a data structure which makes it easy to store and recover what you need to know. Depending on the kind of data in @array, you may want to push indexes or references to elements rather than copying. That will assist in remembering where each element came from, too.
If the first match is the important one, last will bail out of the inner loop, saving unwanted tests.
After Compline,
Zaxo
In reply to Re: Efficiency: Foreach loop and multiple regexs
by Zaxo
in thread Efficiency: Foreach loop and multiple regexs
by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |