Testing for String inclusion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhubabu parumala
    New Member
    • Jul 2007
    • 2

    Testing for String inclusion

    this is my questoon

    $error = ' hi this is madhu babu hou r u ';
    $error1 =' madhu babu';


    now i want check $error1 exists in $error

    there might be space between madhu & babu
  • pnsreee
    New Member
    • Apr 2007
    • 34

    #2
    Hi madhubabu

    The following code may give answer to ur question

    [CODE=perl]
    if ($error =~ m/$error1/) {
    print " OK \n";
    }
    [/CODE]

    Regards
    Pnsreee
    Last edited by miller; Jul 31 '07, 07:02 PM. Reason: Code Tag and ReFormatting

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      Originally posted by madhubabu parumala
      this is my questoon

      $error = ' hi this is madhu babu hou r u ';
      $error1 =' madhu babu';


      now i want check $error1 exists in $error

      there might be space between madhu & babu
      Next time you need help with your school/course work, post the code you have written so far. pnsreee was nice enough to give you a suggestion, but in general we do not help people that have shown no effort, especially when the question is as basic as yours.

      Regards,
      Kevin

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Agreed! You need to post the code you have tried. Also, correct me if I am wrong kevin, but I don't think that variables will interpolate inside of a regular expression, will they? (I could be wrong as I have never though of trying)

        Regards,

        Jeff

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          Yes, variables will interpolate inside of "m" and on the left side (the search side) of an "s" regular expressions, but not "tr". It is very common to use a scalar as a search pattern. To get variables to interpolate on the replacement side of an "s" regexp you have to use the "e" (as in eval) modifier.

          Comment

          Working...