|
fuktfursten Beginner
Joined: 17 Apr 2007 Posts: 20
|
Posted: Thu Feb 12, 2009 5:41 pm
#IF ($var1=~ $var2) |
Im having the worst brain fart ever... can someone help me with my problem?
Code: |
$var1 = "some_value"
$var2 = "value"
#IF ($var2 =~ $var1) {#ECHO Match!} // Prints: Match!
|
but ....
Code: |
#IF ($var1 =~ $var2) {#ECHO Match!} // Wont match
|
... well heres where the brain fart comes in
How would I check to see if the two local variables are identical? In the example I don't want those two values to match like in the first example... but I would want to match the following
Code: |
$var1 = "value"
$var2 = "value"
#IF (?????) {#ECHO Match!}
|
Best Regards
//Fuktfursten |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Feb 12, 2009 5:46 pm |
Code: |
#if ($var1 = $var2) {#ECHO Match!} |
or:
Code: |
#if ($var1 == $var2) {#ECHO Match!} |
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Feb 12, 2009 5:49 pm |
Unless I'm having one too.. this should do it.
Code: |
#IF ($var1 == $var2) {#ECHO Match!} |
Technically speaking this
Code: |
#IF ($var1 == $var2) {#ECHO Match!} |
would work also, but I prefer the first one. It avoids confusion for those who work in multiple languages. |
|
_________________ Asati di tempari! |
|
|
|
fuktfursten Beginner
Joined: 17 Apr 2007 Posts: 20
|
Posted: Thu Feb 12, 2009 6:21 pm |
Thanks guys.
The brain fart was even worse than I thought.. I tried to compare "Value" with "value"
Some days you just shouldn't be allowed to sit at a computer |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Feb 13, 2009 12:46 am |
Incidentally, the thing you were having with =~ is because =~ is looking for a pattern match, not a straight equality. It's treating $var2 as a pattern (you can use wildcards in them) to look for inside $var1, which is why it works in the first instance but not the second. "some_value" contains "value", but "value" doesn't contain "some_value".
|
|
|
|
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Fri Feb 13, 2009 1:19 am |
Tech, your two lines were exactly the same... (I think what you were getting at is use == instead of =.)
You could use #if (@var1 ~= @var2 || @var2 ~= @var1) , although I don't know how well ~= does performancewise. |
|
|
|
|
|