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...


In reply to Re: Match first word in line fails by frostman
in thread Match first word in line fails by yacoubean

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.