Appending to an existing record
To append data to an existing value Tcl provides the dict lappend
command. The syntax is as follows:
dict lappend name key value…
How to do it…
In the following example, we will create a dictionary containing a collection of key/value pairs and then using the dict lappend
command we will append items to the key referenced. Return values from the commands are provided for clarity. Enter the following command:
% set test [dict create 1 1 2 2 3 3] 1 1 2 2 3 3 % dict lappend test 2 more 1 1 2 {2 more} 3 3
How it works…
The dict lappend
command appends the data stored in value
for the key referenced in key
for the dictionary specified in name
.