CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Perl/ CGI (http://www.codingforums.com/forumdisplay.php?f=5)
-   -   Pattern matching (http://www.codingforums.com/showthread.php?t=6288)

j-dogg 09-16-2002 10:24 PM

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.

Inci 09-16-2002 11:44 PM

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..

myuri995 02-27-2005 05:23 AM

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,

mlseim 02-27-2005 04:23 PM

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.