TCL hash wildcard usage?

Viewed 50

Assume we have a 2D hash.

set a(1,x) abc
set a(2,x) def

Now I want to know if 'x' exists in both. I can do :

info exists a(1,x) && info exists a(2,x)

I can put this into a loop but that starts to look clunky.

Is there a way to wildcard ? This naive idea obviously doesn't work.

info exists a(*,x)

Any solution?

1 Answers

You want the array names command here:

set all_names [array names a]
set x_names [array names a "*,x"]    ;# quotes not strictly required here

if {[llength $all_names] == [llength $x_names]} {
    puts "all array keys have x"
} else {
    puts "some array keys don't have x"
}
Related