Passing arrays to procs in Tcl
Archive - Originally posted on "The Horse's Mouth" - 2004-11-18 06:17:00 - Graham EllisIf you're writing a Tcl proc, you'll normally pass in parameters by value, specifying a $ in front of the variable whos contents you want to pass in in the calling sequence:
dojob $passin
If, however, passin is a Tcl array, tis won't work since $passin cannot be expanded to string. So you'll need to make the call using:
dojob passin
and then use upvar within the proc to access the data.
INDIVIDUAL ELEMENTS of an array CAN be passed in to a Tcl Proc by value as they're simple strings:
dojob $passin(demo)
or dojob $passin($elname)
References: our Procedures and Variable Scope and Tcl Array modules