Updated 2012-06-09 14:41:11 by AMG

WJG (09/06/12) Sometimes I need to add values to an existing array. Here's a simple way to do it.
#---------------
# append item(s) to an array of unknown size
#---------------
# args:
#        a        array to append value
#        v        value to append
# returns:
#        adjusted size of the array
#
proc array:append {a v} {
        
        foreach j $v {
                set i [array size $a]
                set ${a}($i) $j
        }

        return $i
}

array:append ::tmp apple
array:append ::tmp [list BANNANA CHERRY DAMSON ]
array:append ::tmp [list elderberry fig grape ]
parray tmp

AMG: What is the benefit of using Tcl arrays in this fashion? What does this do that lists don't?