Updating variables from a dictionary
To update the values stored within a dictionary Tcl provides the dict set
command. The syntax of this command is as follows:
dict set name key value… key value…
How to do it…
In the following example, we will create a dictionary containing collections of key/value pairs and then using the dict set
we will update a stored value. Return values from the commands are provided for clarity. Enter the following command:
% set test [dict create 1 John 2 Mary 3 Paul]
1 John 2 Mary 3 Paul
% dict set test 2 Martha
1 John 2 Martha 3 Paul
How it works…
The dict set
command updates the value stored for the key
in the dictionary referenced to by the name
argument.
Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.