Longer, possibly more efficient way:
re = array.join('|')
s.gsub!(/(#{re})/, "*")
The second way is probably more efficient, since it can
optimize the match and do it in one pass.
not sure if that would scale up to a 10000 entry array though…
Ryan Pavlik rpav@users.sf.net
“And I’m 10,000 feet up in the air. Dang it.” - 8BT
kind regards- botp
···
Ryan Pavlik [mailto:rpav@nwlink.com] wrote:
> > The second way is probably more efficient, since it can
> > optimize the match and do it in one pass.
>
> not sure if that would scale up to a 10000 entry array though..
This is a good point… it wouldn’t. OTOH, it depends on the
problem; the first way would likely be poor for a few words on
many megs of text; the second would be worse in the way you
mentioned.
The first is probably the best for the general case, since even
though it would be poor for huge amounts of text, it would
eventually get done. Of course, you could opt for a hybrid
solution (experiment with COUNT for best results):
COUNT = 20
i = 0; loop {
re = array[i...i+COUNT].join('|')
s.gsub(re, '*')
i += COUNT
break if(i >= array.size)
}

···
On Wed, 25 Jun 2003 15:52:07 +0900 “Peña, Botp” botp@delmonte-phil.com wrote:
–
Ryan Pavlik rpav@users.sf.net
“I sure as hell didn’t learn anything, if thats what you mean.” - 8BT