#!/usr/bin/perl use strict; use warnings; my $blacklist_file = "blacklist.txt"; my @blacklist_entries; sub debug { print @_; } sub read_blacklist { return 1 if @blacklist_entries; open( my $fh, '<', "$blacklist_file" ) or debug( 1, "Can't read '$blacklist_file', $!\n" ); my @lines = grep { !/^\s*\#/ } <$fh>; chomp @lines; close $fh; debug( "No blacklists?\n" ) unless @lines; foreach my $line (@lines) { $line =~ s/^\s*//; $line =~ s/\s*[^\\]\#.*//; next unless $line; push @blacklist_entries, $line; } debug( "No entries in blacklist file?\n" ) unless @blacklist_entries; return 1; } sub testspam { my $comment = shift; chomp $comment; use Encode; read_blacklist(); for my $black (@blacklist_entries) { utf8::decode($black); utf8::decode($comment); #Encode::decode('utf-8',$black); #Encode::decode('utf-8',$comment); if ( $comment =~ /\b\Q$black\E\b/i ) { return "badword_comment $black"; } } } binmode(STDOUT, ":utf8"); while ( my $line = <> ) { my $t = testspam($line); print "$line # $t\n" if length $t; }