Link to home
Start Free TrialLog in
Avatar of thomaszhwang
thomaszhwangFlag for United States of America

asked on

Perl Cotains

I have a sentence x and I have a list of words.  I want to test if any of the words is in the sentence.  Can I test as follow?  Thanks.

for($i = 0; $i < $#words; $i++) {
if($sentence =~ $words[$i]) {
      //There is a match!
}
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thomaszhwang

ASKER

Actually there are metacharacter in the @words.  What should I do in this case?
I just want to do a simple CONTAINS test.  Thanks.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.