dejagnu
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH: Avoid use of [string match] to test strings for equality in r


From: Ben Elliston
Subject: Re: PATCH: Avoid use of [string match] to test strings for equality in runtest.exp
Date: Thu, 6 Dec 2018 13:00:53 +1100
User-agent: Mutt/1.9.4 (2018-02-28)

On Wed, Dec 05, 2018 at 07:03:53PM -0600, Jacob Bachmeyer wrote:

> Older versions of Tcl may have required this use of [string match],
> but modern Tcl allows the much simpler "==" operator.  According to
> time(n), "==" is also slightly faster in "if" expressions in
> addition to being more robust against "odd" inputs.

On the contrary, using '==' is very problematic because it treats the
strings as numerial arguments. Consider:

% set str 0x10
0x10
% if {$str == "16"} { puts yes }
yes

Furthermore, you shuld use 'string equals' for literals as 'string
match' permits patterns.

Cheers,
Ben

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]