Output:my @badwords = ( '31337', 'hacker' ); my @exceptions = ( 'perl_31337_hacker', ); my $string = 'I am a 31337 hacker. A perl_31337_hacker, that is, not a + c_31337_hacker.'; my @occurences = (); my ($word, $oldword, $badword); foreach $word (@badwords) { push(@occurences, $string =~ /\b\S*$word\S*\b/g); } my %exceptions; @exceptions{@exceptions} = @exceptions; foreach $word (@occurences) { if ( !exists ($exceptions{$word}) ) { $oldword = $word; foreach $badword ( @badwords ) { $word =~ s/$badword/<censored>/g; } $string =~ s/$oldword/$word/; } } print $string;
e-MotionI am a <censored> <censored>. A perl_31337_hacker, that is, not a c_<c +ensored>_<censored>.
In reply to Re: Defenetly a complicated perl recipie with 2 arrays, 1 scaler and some special matching
by Anonymous Monk
in thread Defenetly a complicated perl recipie with 2 arrays, 1 scaler and some special matching
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |