in reply to Match first word in line fails
Well yacoubean, I wish I could be more help but it's 2 in the morning and all I could think of is the following, which is food for thought at best.
#!/usr/bin/perl # hmm, try bleeping... use strict; my @badwords = qw(crud poop darn); my $cleanbook; # i wonder if it will work... my $match = join("|",@badwords); # lazy, not checking badwords. while (<DATA>) { # ahh, inefficiency! while ($_ =~ /$match/i) { my $bad = $&; (my $bloop = $bad) =~ s/(?<=\w)\w/\*/sg; $_ =~ s/$bad/$bloop/sg; } $cleanbook .= $_; } print $cleanbook; __DATA__ "Crud," said Travis. But then, Travis was always something of a poopy-head. He could never keep to his darned self. Darn it Travis!
This gives me:
[frost@louddrunk]$ perl t.pl "C***," said Travis. But then, Travis was always something of a p***y-head. He could never keep to his d***ed self. D*** it Travis!
...which may or may not be useful in your case. I was just thinking that if I were in your shoes I'd probably rather bl**p the profanities than replace them with gentler versions.
Erasing them requires too much skill with Grammar::Parse, and replacing them with other words is, well, putting words in people's mouths.
On the other hand, the profane among us are quite used to the occasional obfuscation...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Match first word in line fails
by frostman (Beadle) on Jan 31, 2005 at 01:43 UTC |