Dict
The Tcl dict
command provides simple management
of dictionary values.
Dict is fairly straightforward to use with an array, eg.
array set U {
tom { Name "Tom Brown" Sex M Age 19 Class {4 5} }
mary { Name "Mary Brown" Sex F Age 16 Class {5} }
sam { Name "Sam Spade" Sex M Age 19 Class {3 4} }
}
dict set U(tom) Sex F
dict append U(sam) Name " Jr"
dict lappend U(sam) Class 5
dict incr U(mary) Age
dict set U(tom) Sax Y; # Creates a new field
dict set U(bill) Sax N; # Creates a new entry.
parray U
However, dict is more complex to use with nested dictionaries
and has various other gotchas
(see TreeVsDict for details)
© 2008 Peter MacDonald