I'm going through a crash course in TCL and I'm running into a problem with arrays in TCL. I have two classes, say A and B. In class B I have a method that updates a local array. The format for the array is something like this:
filterData(1) = 23904890234009
filterData(2) = 28974501002990
filterData(3) = 69398018930453
... and it stops there. Only 3 indices. In class A, I instantiate a B object and run a method on it to update the local array. The method inside class B looks like this:
method addData {} {
lappend filterData($type) $data
}
The $type variable is a number 1-3, and the $data variable is a string of numbers. Whenever I run this method and print the arrays contents, it has nothing in it, like it's a new array. What's strange is I have other local variables (lists, strings) in class B that I do the same operation to that are persistent unlike this array which seems to be resetting itself. Any ideas as to how I may be handling this incorrectly? If more info is needed, I can provide.
method
suggests that this is one of the object-oriented extensions of Tcl. Regular Tcl uses dynamic scope which means that a variable inside aproc
is not the same as a variable with the same name outside it. To be able to tell what's what for you we need to know what kind of OO extension you use. – Peter Lewerin