Narek
Narek

Reputation: 39881

How to replace/reset an element value in a TCL array?

Say I have an array in a TCL, and I want to change the value of the element which has a key say "First_elem". How I can do this?

Upvotes: 2

Views: 6525

Answers (1)

überjesus
überjesus

Reputation: 824

Just set the array element like any other variable: set myArray(key) "value"

Here's a more complete example:

array set myArray {
    key1 1234
    key2 5678
}

echo $myArray(key1)
set myArray(key1) "test"   // Change an existing element
set myArray(key3) "hello"  // Add a new element
echo $myArray(key1)

Upvotes: 5

Related Questions