Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 2nd, 2001, 05:59 AM
nimr0d nimr0d is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Netherlands
Posts: 7 nimr0d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy arrays and vars in regexps :|

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

Reply With Quote
  #2  
Old July 2nd, 2001, 06:56 AM
MattWilliams MattWilliams is offline
hmmmm...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: UK
Posts: 37 MattWilliams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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..

Reply With Quote
  #3  
Old July 2nd, 2001, 09:39 AM
nimr0d nimr0d is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Netherlands
Posts: 7 nimr0d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #4  
Old July 2nd, 2001, 10:24 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
I suggest using \b$i\b

\b\b == word boundries, btw

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > arrays and vars in regexps :|


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway