By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,426 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

how to compare with a word only in a sentence?

100+
P: 170
hi all,

if i got a string say

i feel like going to swim today

if i have input say "swim"

and i wanna compare it with the sentence above, it will return true and go on to the rest of the program

cos normally we do this:

if ( swim eq sentence)

it will be true only if it matches the whole sentence so now i just it to return true as long as the sentence has the word swim and carry on with the program

any way in perl we can do this?
Apr 28 '08 #1
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
use a regexp:

Expand|Select|Wrap|Line Numbers
  1. if ($foo =~ /pattern/) {
  2.    do something;
  3. }
  4.  
  5.  
where $foo is the sentence and pattern is "swim". There are plenty of online resources to guide you with learning regular expressions.
Apr 28 '08 #2

100+
P: 170
use a regexp:

Expand|Select|Wrap|Line Numbers
  1. if ($foo =~ /pattern/) {
  2.    do something;
  3. }
  4.  
  5.  
where $foo is the sentence and pattern is "swim". There are plenty of online resources to guide you with learning regular expressions.
thanks a lot once again :)
Apr 28 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.