Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
fuktfursten
Beginner


Joined: 17 Apr 2007
Posts: 20

PostPosted: 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
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Feb 12, 2009 5:46 pm   
 
Code:
#if ($var1 = $var2) {#ECHO Match!}

or:
Code:
#if ($var1 == $var2) {#ECHO Match!}
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: 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!
Reply with quote
fuktfursten
Beginner


Joined: 17 Apr 2007
Posts: 20

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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".
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net