list doesn't contain its own members in Tcl
-
30-06-2021 - |
Question
I have a list containing one member, that member is the string <cmd_stichstudy1>XXDDR0_MA[12]
. When I search for that string in the list (using lsearch
) I get that the list doesn't contain it. I even get it when I search for the member of the list:
tcl> set nets_names
{<cmd_stichstudy1>XXDDR0_MA[12]}
tcl> lsearch $nets_names [lindex $nets_names 0]
-1
Why does this happen?
Solution
If you use -exact it will work the way you want.
% set nets_names {<cmd_stichstudy1>XXDDR0_MA[12]}
<cmd_stichstudy1>XXDDR0_MA[12]
% lsearch -exact $nets_names [lindex $nets_names 0]
0
%
OTHER TIPS
lsearch
has an unfortunate property of using glob-style matching by default.
To cite the manual:
If all matching style options are omitted, the default matching style is -glob.
So always pass -exact
to lsearch
unless you really want -glob
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow