penguin
2013-Jan-11 15:50 UTC
[asterisk-users] Single = sign and double == sign.What is the difference and when to use the two properly?
quick question that leaves alittle confusion here. Im confused on the difference or when to use the other if i have 1 = sign or 2 == signs .. so If i had exten => _XXXX,1,answer() same=> n,Set($[${a}==1]?true:false] <--double equal sign same => n(true),Goto(main,s,1) same=> n(false), Hangup() would this be saying the same thing as above then? exten => _XXXX,answer() same=> n,Set($[${a}=1]?true:false] <-- single equal sign in essence wouldn't i get the same result ? im confused on the double and single equal sign and when to use the difference of the two. Would i get the same result in both these expressions? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20130111/f8313062/attachment.htm>
A J Stiles
2013-Jan-11 17:20 UTC
[asterisk-users] Single = sign and double == sign.What is the difference and when to use the two properly?
On Friday 11 January 2013, penguin wrote:> quick question that leaves alittle confusion here. Im confused on the > difference or when to use the other if i have 1 = sign or 2 == signs .. so > If i had > > exten => _XXXX,1,answer() > same=> n,Set($[${a}==1]?true:false] <--double equal sign > same => n(true),Goto(main,s,1) > same=> n(false), Hangup() > would this be saying the same thing as above then? > > exten => _XXXX,answer() > same=> n,Set($[${a}=1]?true:false] <-- single equal sign > > in essence wouldn't i get the same result ? im confused on the double and > single equal sign and when to use the difference of the two. Would i get > the same result in both these expressions?Generally, one = sign means you're telling. Two == signs means you're asking. It's amusing (for sadists) to see ex-BASIC programmers trip up over this and write something like this: if (denominator = 0) { printf ("Can't divide by zero!\n"); } else { answer = numerator / denominator }; This will never print "Can't divide by zero!" because you are actually assigning a value to a variable right there in the conditional, and returning the assigned value. Since this is zero, the if() will fail and drop through to the else clause -- and then, just to confuse you, the program will crash with "Floating point exception" anyway. -- AJS Answers come *after* questions.
Eric Wieling
2013-Jan-11 19:49 UTC
[asterisk-users] Single = sign and double == sign.What is the difference and when to use the two properly?
In Asterisk extensions.conf and extensions.ael inside $[] "=" and "==" are the same comparison operator. I can't quote where I saw this, but it has been documented somewhere. The == was added to make things more "programmer friendly". -----Original Message----- From: asterisk-users-bounces at lists.digium.com [mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of penguin Sent: Friday, January 11, 2013 10:50 AM To: asterisk-users at lists.digium.com Subject: Re: [asterisk-users] Single = sign and double == sign.What is the difference and when to use the two properly? quick question that leaves alittle confusion here. Im confused on the difference or when to use the other if i have 1 = sign or 2 == signs .. so If i had exten => _XXXX,1,answer() same=> n,Set($[${a}==1]?true:false] <--double equal sign same => n(true),Goto(main,s,1) same=> n(false), Hangup() would this be saying the same thing as above then? exten => _XXXX,answer() same=> n,Set($[${a}=1]?true:false] <-- single equal sign in essence wouldn't i get the same result ? im confused on the double and single equal sign and when to use the difference of the two. Would i get the same result in both these expressions?