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

Ben Elliston <[email protected]>
Newsgroups gmane.comp.sysutils.dejagnu.general
Message-ID <20181206020053.GA18640@bapbop>
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

_______________________________________________
DejaGnu mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/dejagnu
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEFS8+rdM1/2KWERKFZ9rcPj90NkkFAlwIgtQACgkQZ9rcPj90
NkmgqA//V1YTj1y+kEEvQMFc7cHRDgQIj2xQFdlwxWA/5nRrdHDLH6erfw0FXrjc
gKKMd6MhVzS0mScgbAsqQyQCrfKCdmgkhV4zB/Iz8UHVKM/K3nsd71WSfTALBDQd
+PhV1Rfq9DS7f27ql5RBH8xn/PfNRQoTR2UUoAyLodIpwogo7tA589BtlAhcrRh4
18MoaoKbuRqBOMocN9lIaSJbmH6rjj3sHPSjjJSa6SqD/SdtoRPxwN34C16kMQMk
qp7Hi5etagPhIcju5Jypvkm7b6M5s+ir5EoBhtgQGliTFBSVZpieoAzqZFNHUarI
nfNuYEuYTaALPSWaK300Cm2vIJ4ibUyJk3G0Lu3X42XpogMQOwoRmaxeX1JyIVgf
Xx41fSnWzJZEtiNsIlnR3V9eWCLPehSBk8robAQn3xyiu8ILb2WJjDP8ejNc3F9S
D3GDiKYx52II2p8JA6SMWnu1C8hWQgzPDTYBVWDmyus73lP1TmH8RW0oqiABziTg
FH9+WTJe6lfbfiK702E/UAPLxq1kpDlfpfpWE353AZ4gX9Q0dCfNEUc78Xa9Of/c
TRJf/6QZO2hPHANss09VBCIyxtnbfT42Zm/dw4HZ0HWxYWfaFPqflXh3Sy9dzcSo
Dsa8odRtaZe8B8ZCeou6W9bz+iMHaVW6DknZ4bmMCq2oufeg99g=
=pQh7
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.