DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
(1tcl) commands by type

Keyed lists

Keyed lists provide a structured data type built upon standard Tcl lists. This provides a functionality similar to structs in the C programming language.

A keyed list is a list in which each element contains a key and value pair. These element pairs are stored as lists themselves, where the key is the first element of the list, and the value is the second. The key-value pairs are referred to as fields. This is an example of a keyed list:

   {{NAME {Frank Zappa}} {JOB {musician and composer}}}
If the variable person contained the above list, then keylget person NAME would return {Frank Zappa}. Executing the command:

keylset person ID 106

would make person contain:

   {{ID 106} {NAME {Frank Zappa}} {JOB {musician and composer}}
Fields may contain subfields; ``.'' is the separator character. Subfields are actually fields where the value is another keyed list. Thus, the following list has the top level fields ID and NAME, and subfields NAME.FIRST and NAME.LAST:
   {ID 106} {NAME {{FIRST Frank} {LAST Zappa}}}
There is no limit to the recursive depth of subfields, allowing you to build complex data structures.

Keyed lists are constructed and accessed by a number of commands. All keyed list management commands take the name of the variable containing the keyed list as an argument (that is, passed by reference), rather than passing the list directly.

Available commands are:


keyldel(1tcl)
deletes a key and value from a keyed list

keylget(1tcl)
returns the value associated with a key from a keyed list

keylkeys(1tcl)
returns the list of keys in the keyed list

keylset(1tcl)
sets the value of a key in a keyed list

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004