in reply to Using a variable as pattern in substitution
You could do it with the loop, as you've hinted:
Another possibility is to combine the words into a single regex, and apply it once (note, this is untested):foreach my $stopword (@stop_words) { $date =~ s/\b$stopword\b//g; }
Whether that will be faster depends a lot on the number of words, their lengths, and the length of the input string. Give each a try. You may also want to see if using the study function improves things any.my $stop_pat = '\b(' . join('|', @stop_words) . ')\b'; $data =~ s/$stop_pat//g;
HTH
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Using a variable as pattern in substitution
by Popcorn Dave (Abbot) on Jun 05, 2002 at 18:13 UTC | |
by VSarkiss (Monsignor) on Jun 05, 2002 at 18:30 UTC | |
|
Re: Re: Using a variable as pattern in substitution
by stew (Scribe) on Jun 05, 2002 at 15:46 UTC | |
by VSarkiss (Monsignor) on Jun 05, 2002 at 16:21 UTC | |
by Aristotle (Chancellor) on Jun 05, 2002 at 17:12 UTC |