I want to filter bad words from the input fields in a script. I came up with a code that works, but I'm sure one of you can give me a better solution (my code would probably take many server resources if the badword list is bad).
Thanks for any suggestions!
Perl code:
#!/usr/bin/perl
$input1 = "ASDkj aslkjflkaj asflkjlksaj BADWORD afasf";
$input2 = "sdgsdgj BADWORD2 petzi BADWORD afsht";
$input3 = "ljha BADWORD3 auzisf opuzip asf";
open (TXTFILE, "badwords.txt"
;
while (<TXTFILE>) {
chomp;
$input1 =~ s/\s$_\s/ /ig;
$input2 =~ s/\s$_\s/ /ig;
$input3 =~ s/\s$_\s/ /ig;
}
close(TXTFILE);
print "Content-type: text/html\n\n";
print "$input1<br>\n";
print "$input2<br>\n";
print "$input3\n";
File with bad words:
BADWORD
BADWORD1
BADWORD2
BADWORD3
etc...
Thanks for any suggestions!
Perl code:
#!/usr/bin/perl
$input1 = "ASDkj aslkjflkaj asflkjlksaj BADWORD afasf";
$input2 = "sdgsdgj BADWORD2 petzi BADWORD afsht";
$input3 = "ljha BADWORD3 auzisf opuzip asf";
open (TXTFILE, "badwords.txt"
while (<TXTFILE>) {
chomp;
$input1 =~ s/\s$_\s/ /ig;
$input2 =~ s/\s$_\s/ /ig;
$input3 =~ s/\s$_\s/ /ig;
}
close(TXTFILE);
print "Content-type: text/html\n\n";
print "$input1<br>\n";
print "$input2<br>\n";
print "$input3\n";
File with bad words:
BADWORD
BADWORD1
BADWORD2
BADWORD3
etc...