Richard Bagshaw schreef:

> @words = $sentance =~ m/[A-Za-z]+/gi;

Because of the /i, you don't need to mention the capitals.

Alternatives:

  @words = ($sentence =~ m/\S+/g);

  @words = split ' ', $sentence;


  @words = ($sentence =~ m/[[:alpha:]]+/g);

  @words = split /[^[:alpha:]]+/, $sentence;

(that last one would split up "shit_head" into "shit" and "head")


> foreach(@words) {
>
>         # first check :: passes words that contain swear words as
>         long as # they have characters either side. ie (harassment).
>
>         # second check :: if the first check is passed then it checks
>         again # for swear words.
>
>         # third check :: if it gets through to here then its
> assumemed a nice
>         # word.
>
>         if (m/[a-zA-Z].*(ass|fuck|cunt|shit)[a-zA-Z].*/gi) {
>                 print "Good Word [boxed]  : $&\n";
>         } elsif (m/ass|fuck|cunt|shit/gi) {
>                 print "Bad  Word [found]  : $_\n";
>         } else {
>                 print "Good Word [passed] : $_\n";
>         }



Alternative:

    $bad = qr/a[s$][s$]|f[u*]ck|cunt|sh[i1]t/i;

    for (@words) {
        if ( m/$bad/ ) {
            if ( m/\b$bad\b/ ) {
                print "Bad  Word [found]  : $_\n";
            } else {
                print "Good Word [boxed]  : $_\n";
            }
        } else {
                print "Good Word [passed] : $_\n";
        }
    }


But you'ld better go this way:

#!/usr/bin/perl
  use strict;
  use warnings;
  use Regexp::Profanity::US;

  my $RE = $RE{profanity}{us}{normal}{label}{-keep}{-dist=>3};

  while (<>) {
      warn "PROFANE:$1" if /($RE)/;
  }


-- 
Affijn, Ruud

"Gewoon is een tijger."



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to