|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
What's the difference between an for array variable and a normal variable?
In this perl code I load a list of words in @wordlist. That works. Then I loop through the list trying to match it with $form_msg. Code:
open(WORDFILTER, "$dir_cgi/$site.mod.words.txt") or ExitError ("Error opening $dir_cgi/$site.mod.words.txt");
@wordlist = <WORDFILTER>;
close (WORDFILTER);
for $i (@wordlist) {
#$i = "piss";
if ($form_msg =~ /$i/) {
$outfile = "$dir_cgi/$site.mod.txt";
}
It works if I do $i = "word";. But not with the array var. This is for a profanity filter. Thx, Nimr0d |
|
#2
|
|||
|
|||
|
you need to use a foreach loop instead of a for loop:
foreach $i (@foulWord) { if ($form =~ m/\w$i\w/ig ) { do this.... } } note the use of white space flags? you have to take into consideration that certain words contain swear words, like Essex -> SEX etc.. |
|
#3
|
|||
|
|||
|
Thanx
Thanx, i''l try this tomorrow.
Btw. it's for a guestbook. If it contains any possible foul words, it goes to a moderation queue. The owner can change and add words and set the sensibility of those (like whitespaces and such). Again, thx! |
|
#4
|
|||
|
|||
|
I suggest using \b$i\b
\b\b == word boundries, btw |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > arrays and vars in regexps :| |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|