Version 4 of array set

Updated 2008-03-12 18:57:39 by willdye

array set arrayName list

Sets the values of one or more elements in arrayName. List must have a form like that returned by array get, consisting of an even number of elements. Each odd-numbered element in list is treated as an element name within arrayName, and the following element in list is used as a new value for that array element. If the variable arrayName does not already exist and list is empty, arrayName is created with an empty array value.

Note that if the array has existing elements, array set will append the new elements to the array. The existing elements will not be removed. In contrast, the normal set command will replace all existing data.

For example, array set spam {} will not clear out the array variable spam. In version 8.3 and beyond, you can use array unset instead. For example:

 array unset spam

...will remove the array spam if it exists, but will not complain if it does not.

 array unset spam *

...will clear the contents of the array spam, but the array will continue to exist.


See also:


Category Command - Tcl syntax help