X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FBadWords.pm;fp=perl%2FBadWords.pm;h=ff9dd04c8b4e3b70a634828862420fcac1ccaa8a;hb=8e0eef80216fbb2bca3606daf5797e39b2889d7a;hp=0000000000000000000000000000000000000000;hpb=eef5d189206ebcfaf8e83675803829c72671a320;p=spider.git diff --git a/perl/BadWords.pm b/perl/BadWords.pm new file mode 100644 index 00000000..ff9dd04c --- /dev/null +++ b/perl/BadWords.pm @@ -0,0 +1,54 @@ +# +# Search for bad words in strings +# +# Copyright (c) 2000 Dirk Koopman +# +# $Id$ +# + +package BadWords; + +use strict; + +use DXUtil; +use DXVars; +use IO::File; + +use vars qw(%badwords $fn); + +$fn = "$main::data/badwords"; +%badwords = (); + +# load the badwords file +sub load +{ + my @out; + return unless -e $fn; + my $fh = new IO::File $fn; + + if ($fh) { + %badwords = (); + while (<$fh>) { + chomp; + next if /^\s*\#/; + my @list = split " "; + for (@list) { + $badwords{lc $_}++; + } + } + $fh->close; + } else { + my $l = "can't open $fn $!"; + dbg('err', $l); + push @out, $l; + } + return @out; +} + +# check the text against the badwords list +sub check +{ + return grep { $badwords{$_} } split(/\b/, lc shift); +} + +1;