I've a banned-word list stored in a text file. Each word is stored in a new line The file is saved in Windows and uploaded to a Unix server. The code that attempts to check for banned words is as follows:
In Windows, the chomp line works and I don't have to have the two regex lines to remove the new line. I know it works because when $data contains a banned word, the error sub is triggered.sub filter { my $data = shift; open(FH, "filter") or die $!; my @words = <FH>; foreach my $word (@words) { #chomp $word; $word =~ s/\r//; $word =~ s/\n//; error('bad word found') if ($data =~ /$word/i); } return $data; }
In the unix server, the same script doesn't work with chomp so I replaced it with '$word =~ s/\r//;' and '$word =~ s/\n//;'. Only then does the banned word check work i.e. when $data contains a banned word, the error is triggered.
Maybe I'm too tired...
Thanks for reading :)
update: That explains why I was getting the behaviour I wasn't expecting. Thanks!
In reply to Why chomp doesn't work? by kiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |