webcs
asked on
Detecting a word from a string in Perl
Detecting a word from a string in Perl
give variable $mysentence = "This house is red and not white";
Need a quick routine to check if a word is present in the variable and flag it if it is...
IE....if the word red is in the sentence then wordflag=1 else wordflag=0
Would also be nice if it could handle any case.
thanks
give variable $mysentence = "This house is red and not white";
Need a quick routine to check if a word is present in the variable and flag it if it is...
IE....if the word red is in the sentence then wordflag=1 else wordflag=0
Would also be nice if it could handle any case.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if ($mysentence =~ /word/i) {$wordflag=1;} else {$wordflag=0;}
--Zyloch