![]() |
Pattern matching
Hi
I have a string that I want to check for the presence of another string. The only problem is, both strings are stored in variables. How can I do this? I'm assuming I can't just say if ($string1 =~ /$string2/) because this will search for the actual string "$string2". Thanks in advance. |
Hello,
well if the string you would like to check for presence of another string located in $string1 variable and checking stuff located in $string2 variable - your regular expression is correct.. if you want to search without capitalization you have to add /i modifier to the end of your regular expression like this: if ($string1 =~ /$string2/i) hope this will help you.. |
Same problem
I have the same problem as J-dogg,
when I type $string2 the value of the $string2 (in my case $string2 = 27) is not taken, instead it tries to search for "$string2" (not 27) in the $string1 string. Can you please help me.... Thank you, |
When using compares with strings,
also make sure you use "eq" and "ne" (equal and not-equal) instead of == for strings: if($string1 eq $string2){ print "they are equal.";} if($string1 ne "orange"){ print "they are NOT equal.";} for integers: if($xpos == $ypos){ print "the two positions are equal.";} I don't know if this helps with your question, but just something to keep in mind. |
| All times are GMT +1. The time now is 12:09 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.