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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem reconstructing variable

Status
Not open for further replies.

Thodd

Technical User
Oct 21, 2006
27
BE
Hi,
I'm a newbie in Tcl. I want to return the value of node1 & node2 on screen by a for-loop. But I don't really know how to manage this...

set ns [new Simulator]

set node1 "ok1"
set node2 "ok2"
...
for {set i 1} {$i <= 1} {incr i} {
set clientnode "node"
append clientnode $i
puts $clientnode
}

$ns run

This returns "node1" instead of "ok1".
Thx in advance
 
This is a common mistake; at least, I made it often enough. You need to use eval to force the secondary substitution:
Code:
puts [eval "set $clientnode"]

_________________
Bob Rashkin
 
Ok, thx!
I'll try your solution.
 
Thx it works!
Now I've got another problem here:

set ns [new Simulator]
...
for {set i 1} {$i <= 1} {incr i} {
set agentname "udp"
append agentname [expr $i + 1]
set agentname [new Agent/UDP]
...
set agentnameb [expr append $agentname "b"]
puts $agentnameb
}

$ns run

it should then return udp2b instead of the value of that variable.
What went wrong?
Thx
 
set agentnameb $agentname;append agentnameb b

_________________
Bob Rashkin
 
By the way, expr is only used for evaluating mathematical expressions, as in:
set FofX [expr {$a*pow($x,2)}]

_________________
Bob Rashkin
 
Exactly, but sometimes I'm still very confused by the tcl-syntax...

thx for noticing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top