In my TCL script I am passing an empty list as argument to a proc. Inside the proc, I am adding values to the list. But outside of that proc, the values of list is not reflected. How can I access the same list which is modified within the proc ?
Note : I do not want to return from the proc due to some reasons which I have not mentioned here in the interest of keeping my requirement simple.
proc addNames { names } {
lappend names tom
lappend names harry
puts $names
}
set names {}
addNames $names
puts "Outside of proc: names"
puts $names
If you don't want to use
returnin your proc, then you could useupvare.g.However, note that this creates a dependency in your proc on the existence of
namesin the calling environment. A more flexible approach might be to pass in a parameter with the name of thenamesvariable: