Getting a record

While the dict for command is generally used for processing multiple key/value pairs, Tcl provides the dict get command to obtain the value assigned to a specific key. The syntax is as follows:

	dict get dictionaryValue key

How to do it…

In the following example, we will create a dictionary containing a set of key/value pairs and then, using the dict get command, obtain the value associated with the specified key. Return values from the commands are provided for clarity. Enter the following command:


% set names [dict create 1 John 2 Mary 3 Paul]
1 John 2 Mary 3 Paul

% dict get $names 3
Paul

How it works…

The dict get command will retrieve the value associated with the argument contained in the key for the dictionary defined by dictionaryValue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.5.201