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!

TCL Variable substitution problem...

Status
Not open for further replies.

globemast

Programmer
Jun 24, 2006
7
CY
Hello,

I have the following problem regarding TCL variable substitution

I have the following code in ns2:

set Appl_udp_0_1 [new Agent/UDP]
$ns attach-agent $n(0) $Appl_udp_0_1
$Appl_udp_0_1 set class_ 1

where the first number in $Appl_udp_0_1 (i.e 0) characterizes the node the UDP agent is running and the second number (ie. 1) the flow id.

In a procedure i have the following parameters

proc test { src flowid} {

global Appl_udp_$src_$flowid

}

My problem is that TCL takes as variable the $src_ (including the "_" character) and as a result shows that a variable $src_ does not exist.

Is there a way i can make the variable expression to stop before the "_" character ??

Thank you.
 
Try encapsulating the variable name only with {}'s .

e.g. -

set VAR1 "abc"
puts ${VAR1}_123
--> abc_123

... Hope that helps!
 
Ok if i substitute include the variable in curly brackets it recognises the correct variable, but now it gives me another problem.


If i have the following:

$ns detach-agent $n(4) $Appl_udp_${dest}_${flowid}

it tells me that variable Appl_udp_ doesn't exist...

It seems it reads the variable up to the second "_" character.

Any suggestions?


Thank you in advance.

 
Yeah, I think I understand your situation ...

You need to use name spaces "::"

e.g. -

> set VAR1 "dog"
> set X "1"

puts ${VAR}${X}
--> can't read "VAR": no such variable

but, if you do this:

> puts [set ::VAR${X}]
--> dog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top