Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing associative arrays in a tcl proc

Status
Not open for further replies.

stevearas

Programmer
Nov 14, 2001
5
US
I've got a recursive proc with code that access a global associative array. There are many associative arrays using the naming convention Node1, Node2, Node 3 etc...

Because the name has to be dynamically generated

upvar 0 Node[expr $node_nr] MyLocalNode
set thistest $MyLocalNode(NodeID)

I've also tried using the global command like this:

global Node[expr $node_nr]
set thistest ${MyLocalNode}(NodeID)

I've been stuck on this for almost two days. I'm ready to trash this idea and try something completely different. I'd rather not.

More info:

set thistest $Node1(NodeID) works fine

set Node[expr $node_nr](NodeID) 12345 works fine

I think this all revolves around tcls "one pass" elvaluation

Is this possible?
Any help would be GREATLY appreciated.


 
From Author SORRY: Should read

I've also tried using the global command like this:

global Node[expr $node_nr]
set thistest ${Node[expr $node_nr]}(NodeID)

*******************************************

Actually, I've tried every possible combination of brackets and curlys.

I just want to go home :-(

 
From Author:

Well I figured it out. My problem was two bugs. The first was I needed to code the upvar like this

upvar #0 Node[expr $node_nr] MyLocalNode
set thistest $MyLocalNode(NodeID)

The second problem was related because of the recurrsive procs. Each variable group on the stack needed to point at the true global *NOT* the node from the previous call.

As usual I finally figure out these difficult problems after I ask for help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top