Gossamer Forum
Home : General : Perl Programming :

Re: Swear Filter.....

Quote Reply
Re: Swear Filter..... In reply to
No, the split is in @_ not $_. You would have to loop through that array and look at each word.

What you could do is, keep an array of all the words you want to block, then a substituition could get it done.

Please note, this is a very quick example, and im sure that given a little thought there would be a better, more efficient solution, but this is just one way to do it, to get you started.

Note this will only work on exact matches, and not with words embedded within another word

Code:
@swears = qw(blah foo sucks);
$comments = 'This is a tame set of foo words. This comment sucks, but hey...blah.';

print "$comments\n";
$comments =~ s/\b$_\b/'*' x length $_/egi foreach @swears;
print "$comments\n";

Installation support is provided via ICQ at UIN# 53788453. I will only respond on that number.
Subject Author Views Date
Thread Swear Filter..... Paul 12725 Mar 22, 2001, 7:54 AM
Thread Re: Swear Filter.....
Mark Badolato 12564 Mar 22, 2001, 8:19 AM
Thread Re: Swear Filter.....
Paul 12569 Mar 22, 2001, 8:24 AM
Thread Re: Swear Filter.....
cK 12591 Mar 22, 2001, 8:49 AM
Thread Re: Swear Filter.....
Paul 12614 Mar 22, 2001, 8:51 AM
Thread Re: Swear Filter.....
cK 12612 Mar 22, 2001, 9:25 AM
Thread Re: Swear Filter.....
Paul 12572 Mar 22, 2001, 9:56 AM
Thread Re: Swear Filter.....
Stealth 12571 Mar 22, 2001, 11:12 AM
Post Re: Swear Filter.....
Paul 12568 Mar 22, 2001, 2:31 PM
Post Re: Swear Filter.....
Paul 12568 Mar 22, 2001, 2:37 PM
Thread Re: Swear Filter.....
cK 12550 Mar 22, 2001, 2:37 PM
Post Re: Swear Filter.....
Paul 12537 Mar 22, 2001, 2:42 PM
Thread Re: Swear Filter.....
Paul 12604 Mar 22, 2001, 2:47 PM
Thread Re: Swear Filter.....
cK 12540 Mar 22, 2001, 3:34 PM
Thread Re: Swear Filter.....
Paul 12567 Mar 22, 2001, 3:43 PM
Thread Re: Swear Filter.....
cK 12508 Mar 22, 2001, 5:10 PM
Thread Re: Swear Filter.....
Paul 12579 Mar 23, 2001, 5:41 AM
Thread Re: Swear Filter.....
cK 12467 Mar 23, 2001, 6:11 AM
Thread Re: Swear Filter.....
Paul 12469 Mar 23, 2001, 6:33 AM
Thread Re: [Paul] Swear Filter.....
shiner 12394 Apr 8, 2003, 9:08 AM
Post Re: [shiner] Swear Filter.....
Paul 12361 Apr 8, 2003, 9:17 AM