in reply to Substitute 'bad words' with 'good words' according to lists
You're on the right track, but you have a few issues to deal with --
What's the best solution? I have no idea. More efficient, I might be able to do, but what's the acceptable tradeoff between ease of adding new terms and other maintenance time, execution time, missed terms, incorrectly replaced terms, or whatever other parameters you might have.
I'd have done something like the following, if we were matching on whole words, and we didn't have the other issues I mentioned:
my $regex_string = "\b('. join ('|',keys %words).')\b'; my $regex = qr/$regex_string/; $txt =~ s/$regex/$words{$regex}/eg;
I think there's a module in CPAN that builds better regexes from lists, but I can't remember what it was called. (and depending on how often you rebuild the list, and the number of terms, available memory, etc, this might not be the best way for you)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Substitute 'bad words' with 'good words' according to lists
by mulander (Monk) on Sep 25, 2005 at 18:52 UTC |