Prev: TclDevKit/Starpack failing to load a package DLL
Next: Problems reading from a specific web site
From: Sean Woods on 6 Mar 2010 06:06 In Tcl8.5 (and available as a package for 8.4) the core introduced the concept of "dicts." They are essentially nested key/value lists. If I were to try to pull off your example in 8.5+ I would do it such: set points {} dict set points 0 x 10 dict set points 0 y 20 dict set points 0 z 30 proc print_point point { puts "[dict get $point x] / [dict get $point y] / [dict get $point z]" } print_point [dict get $points 0] (returns) 10 / 20 / 30 dict set points 0 x 35 print_point [dict get $points 0] (returns) 35 / 20 / 30 Hope that helps, Sean "The Hypnotoad" Woods On Mar 5, 9:54 am, CWS <usmgoldenea...(a)gmail.com> wrote: > I have a tcl struct that i have created somewhere in my program like > so: > > set array(0.x) 10 > set array(0.y) 20 > set array(0.z) 30 > > lets say i have 20 of these structs that have been filled with data. > this array is not going to be global, no need for it. i just need to > pass it to the appropriate functions when needed. > > I want to pass this to a proc and be able to retrieve the data(or > print it out) but keep getting errors. i would also like to change > values on the fly so that the original array also changes. I actually > have this part working...so naturally i am confused as to why i cannot > access the array when trying to output it to the screen. > > Can anyone help? Thanks much in advance. > > ***so if i have:*** > > proc print_array {arr} { > > upvar $arr a > > #set a(0.x) 25 <---update this value > > #puts "$a(0.x)" <---Error in startup script: can't read "a(0.x)": no > such element in array while executing "puts "$a(0.x)"" > > } > > and in my main somewhere i have created and filled the array with > values so i call the proc: > > print_array myArray > > puts "$myArray(0.x)" <---this prints out the changed value > successfully from up in the proc.
First
|
Prev
|
Pages: 1 2 Prev: TclDevKit/Starpack failing to load a package DLL Next: Problems reading from a specific web site |