upvar, a built-in Tcl command, links a variable to some other variable at the specified level of evaluation.
i.e If you want to change the value of variable from with in the procedure we can use upvar to do that.
Example:
proc upvar_demo {var1 var2} {
upvar $var1 procvar1
upvar $var2 procvar2
set procvar1 TCL
set procvar2 Script
}
set outvar1 Hello
set outvar2 World
puts "Values of variables before executing the procedure"
puts "outvar1 : $outvar1"
puts "outvar2 : $outvar2"
upvar_demo outvar1 outvar2
puts "Values of variables after executing the upvar procedure"
puts "outvar1 : $outvar1"
puts "outvar2 : $outvar2"
#Output :
Values of variables before executing the procedure
outvar1 : Hello
outvar2 : World
Values of variables after executing the upvar procedure
outvar1 : TCL
No comments:
Post a Comment