On 3/10/06, John W. Krahn <[EMAIL PROTECTED]> wrote: > Jay Savage wrote: > > > > I've actually found it depends partly on architecture, too; the regex > > engine seems better optimized on some platforms than others. I was > > quite surprised once when benchmarking a script on a fairly modern OS > > X/PPC machine (750MHz CRT iMac) and an ancient Linux box (166MHz PII > > Dell Dimension XPS PII running SuSE 9.1)--with both machines running > > 5.8.6--that the regex solution to the problem I was working on ran > > faster on the the Dell, but the index version ran faster on the Mac. > > > > The issue seemed to be the number of function calls. index beat the > > pants off m// on both machines for finding literals, of course, but > > once I had to perform two indexes, combining them both into a single > > regex ran faster on one machine and was only about 1% slower on the > > other. > > > > The relevance here is that once your looking for several things, I'd > > at least want to bechmark the regex, especially since we're firing up > > the regex engine for the first match anyway. > > > > My advice to the OP would be to benchmark all three of the following > > and see which comes out on top for him: > > > > grep /_${feed_date}_.*?\.wav\z/o, @dir_files; > > grep ((index($_, $feed_date) != -1) && (index($_, ".wav") != -1)), > > @dir_files; > > grep /\.wav\z/ && (index($_, $feed_date) != -1), @source_list; > > grep { /_${feed_date}_/ && /\.wav$/ } @dir_files; > > Be careful with those matches to ensure you are matching the same things. For > example, the OP said he had file names something like: > > ABCD_9Mar_somethingelse.wav > ABCD_19Mar_somethingelse.wav > > If $feed_date is '9Mar' then your second and third examples will match both > file names and your second example will also match the file name: > > ABCD_9Mar_some.wavthingelse.pdf > > > > John
The examples, with the exception of my own, were taken from other responses to the thread. As far as that's concerned, your eye was the best. My point, though, was this: benchmark the different options. Especially since, as you point out, index doesn't help you much when you need to anchor the search unless you go to something like 'index($_, ".wav") == (length($_) - 4)' or 'substr($_, -4) eq ".wav"' -- j -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!