in reply to foreach (@array) s/x/y/ efficiency

It might be nice if you could do this, since index and substr should be faster than regexen:
$text = join("\n",@material); for my $phrase (@key_phrases) { my $pos = index $text, $phrase; if ($pos == -1) { warn "Phrase: $phrase not found\n"; } substr($text, $pos, 0) = '<B>'; substr($text, ($pos+length($phrase)), 0) = '</B>'; }
However you quite likely need to ignore case, and judging by your code you have other conditions which this code won't do. Of course you might be able to fix that with use of lc and maybe some preprocessing, but if your doing that you might destroy any speed gains.

Replies are listed 'Best First'.
Re: Re: foreach (@array) s/x/y/ efficiency
by gryphon (Abbot) on Jan 11, 2001 at 02:53 UTC

    Although index runs faster than s///, $phrase is actually two words that may have "stuff" between them (in @material) other than just a space (as they would have in $phrase). So this doesn't match a lot of the phrases. :(