Version 4 of Answered Questions On: Basic Tcl

Updated 2004-10-24 21:38:02

Contents:-

  • What's The Difference Between "==" And "eq"?


WHAT'S THE DIFFERENCE BETWEEN "==" AND "EQ"?

MG April 22nd 2004 - Out of pure curiousity, what (if anything) are the pros and cons of using these different checks in an if {} statement?

  if { $str1 == $str2 } { # do something }
  if { $str1 eq $str2 } { # do something }
  if { [string equal $str1 $str2] } { # do something }

Peter Newman 26 April 2004: I have a Perl background; so have always assumed that "==" is for numbers and "eq" is for strings. So:-

 if { "01" == "1" } should return TRUE, and;
 if { "01" eq "1" ) should return FALSE.

But looking at the expr manpage, who knows? And I'm too lazy to fire up wish and check it out. But I always code on that assumption, and haven't yet encountered anything that suggests it's wrong. Also, I think "eq" is relatively new (Tcl 8.3 for example). So perhaps that explains the apparently redundant string equal $str1 $str2. But don't quote me on any of this. MG Apr 28 2004 - I just checked that in wish, and it seems you're absolutely right. Thanks for the help :)