Version 4 of ne

Updated 2009-08-23 04:58:52 by _hc

Infix operator for string comparison inside expr. Returns true if its arguments are not string-equal.

Its opposite part is eq, which returns true if its arguments are string-equal.

Differs from != in such that its arguments cannot be treated as numerical values, so 1 != 1.0 returns false, but 1 ne 1.0 returns true.

Example:

 % expr {"a" eq "b"}
 0
 % expr {"a" ne "b"}
 1
 %
 % expr {"1" eq "1.0"}
 0
 % expr {"1" == "1.0"}
 1

Also comparing text with ne is faster than !=. From Practical programming in Tcl and Tk, by Brent B. Welch, Ken Jones, Jeffrey Hobbs: "The eq and ne expr operators were introduced in 8.4 to allow more compact strict string comparison. These operations also work faster because the unnecessary conversions are eliminated."