String Compare in Perl? (Most likely reg expression?)
Posted on 2011-04-23
I need to write a perl if statement that compares two strings and if string one is equal to part of string 2 then it return true, otherwise it returns false.
The first string will be a single value such as hello. It could be values such as hello, hello1a, person, dog, etc... to give you an idea.
The second string will be multiple words separated by commas and ending in which space such as: girl, boy2b, cat, hello1a
I need to write code where if string 1 is contained in string 2 (from comma to comma or comma to whitespace) I return true, otherwise I return false. The main thing to consider is the last word will not be followed by a comma but rather nothing and all other word will be separated by a comma.
For example if the word is boy and string to compare is: girl, boy2b, cat then it would return false.
For example if the word is boy2b and string to compare is: girl, boy2b, cat then it would return true.
The thing that makes this more difficult for me is the last word not being separated by a comma and the fact that a word has to be exact. So boy1a is not the same as boy.