how to compare with a word only in a sentence?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    #1

    how to compare with a word only in a sentence?

    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?
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    use a regexp:

    Code:
    if ($foo =~ /pattern/) {
       do something;
    }
    where $foo is the sentence and pattern is "swim". There are plenty of online resources to guide you with learning regular expressions.

    Comment

    • poolboi
      New Member
      • Jan 2008
      • 170

      #3
      Originally posted by KevinADC
      use a regexp:

      Code:
      if ($foo =~ /pattern/) {
         do something;
      }
      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 :)

      Comment

      Working...