How to create hashes of hash in Tcl

Viewed 63

Hope all are doing well.

I am a newbie to the TCL programming language and started working on a project.

I want to create a hash here according to the following table-

enter image description here

I want to create a hash with the name MEM_GROUP and want to access a value DDR1, DDR2, etc. Suppose I want to print DDR3 that comes under the ownership of Person3 then how do I access that?
Please help me.

1 Answers

Use tcl dicts instead of arrays, to start - they're both hash tables under the hood, but the dict interface explicitly supports easy to use nested tables with chains of keys:

#!/usr/bin/env tclsh                                                                                                                                                                                                                             

set mem_group [dict create]
dict set mem_group Person1 ownership DDR1
dict set mem_group Person2 ownership DDR2
dict set mem_group Person3 ownership DDR3
dict set mem_group Person4 ownership DDR4

puts [dict get $mem_group Person3 ownership]
Related