kiat has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why chomp doesn't work?
by Fletch (Bishop) on Jun 13, 2004 at 16:04 UTC | |
by bart (Canon) on Jun 14, 2004 at 13:35 UTC | |
by Fletch (Bishop) on Jun 14, 2004 at 14:14 UTC | |
|
Re: Why chomp doesn't work?
by davido (Cardinal) on Jun 13, 2004 at 16:04 UTC | |
|
Re: Why chomp doesn't work?
by rnahi (Curate) on Jun 13, 2004 at 16:18 UTC | |
by calin (Deacon) on Jun 13, 2004 at 18:05 UTC | |
by bart (Canon) on Jun 14, 2004 at 13:41 UTC | |
|
Re: Why chomp doesn't work?
by thor (Priest) on Jun 13, 2004 at 18:31 UTC | |
by kiat (Vicar) on Jun 13, 2004 at 23:08 UTC | |
|
Re: Why chomp doesn't work?
by thens (Scribe) on Jun 13, 2004 at 16:21 UTC |