array
array subcommand ?arg ...?
The commands for arrays. An array is a variable with elements, each with a name: name(element). An array is a variable and has no value of its own: pass its name, and use array get for a value.
Subcommands
| Synopsis | What it does |
|---|---|
array set NAME LIST |
Sets the elements from a list of names and values. |
array get NAME ?PATTERN? |
A list of names and values. |
array names NAME ?MODE? ?PATTERN? |
The element names. MODE is -glob, -exact, or -regexp. |
array exists NAME |
1 when the variable is an array. |
array for {KEYVAR VALUEVAR} NAME BODY |
Runs BODY once for each element of a copy of the array. Tcl 9.1 only. |
| `array default get | set |
array size NAME |
The count of elements. |
array unset NAME ?PATTERN? |
Removes the elements, or the whole array. |
array statistics NAME |
Text about the hash table. |
array startsearch NAME |
A search id, for the old way to go through an array one element at a time. |
array nextelement NAME ID |
The next element name of the search. |
array anymore NAME ID |
1 when the search has more elements. |
array donesearch NAME ID |
Ends the search. |
Examples
A click on an example runs it in the shell of the page.
array set a {x 1 y 2}; array size a:2set a(x):1lsort [array names a]:x y
Facts
- Capability: none.
- Compute cost: one compute unit for the call, and more for the commands that it runs.