You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_dtcl@tcl.apache.org by "David N. Welton" <da...@innominate.it> on 2001/03/21 16:42:05 UTC

code snippet: creating variables from VAR(...)

namespace eval request {

    proc setvars { args } {
	foreach a $args {
	    set globalvar [ lindex $a 2 ]
	    set arr1 [ lindex $a 0 ]
	    set arrvar "[lindex $a 0]([lindex $a 1])"

	    puts "$globalvar $arr1 $arrvar"
	    variable $arr1
	    if { [ info vars $arr1 ] != "" && [ info exists $arrvar ] } {	    
		upvar $arrvar localvar
	    } else {
		set localvar ""
	    }
	    variable $globalvar
	    set $globalvar $localvar
	}
    }

    set VARS(dtcl) foo

    setvars [list VARS dtcl dtcl]

    puts $dtcl

}

This illustrates a way (that might be improved) to create a variable,
such as 'dtcl' in this example, that is guaranteed to exist, from an
array element like VARS(dtcl)...

-- 
David N. Welton
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/
         Work: http://www.innominate.com/