Re: TCL variable substitution problem

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: TCL variable substitution problem

raimizou

I am not sure if you included the ns-users list in copy of your interesting
comments. I therefore forward it, for security.

Gilles

2006/6/26, Nicholas Loulloudes <[hidden email]>:

>
> Hello Gilles,
>
> thank you for the response and help. It has been clear enough to help me
> understand.
>
> I found out also that if i surround the variable name only in curly
> brackets i can tell TCL what is the exact name of the variable.
>
> for instance i could have : $Appl_udp_${src}_${flowid}.
>
> Doing this allows you to clearly specify the exact name of the variable
> you are interested. But a problem arised if you try now to compile the tcl
> file. The compiler will report an error saying that $Appl_udp_ is not a
> variable.
>
> In order to overcome this someone can use the following [set
> Appl_udp_${src}_${flowid}].
>

You could use expr instead of set. The logic is the same.


I just made a comment on the above solution in case someone in the future

> has the same problem like i did.
>
> Regards,
>
> Nicholas
>
>
> On 6/26/06, Gilles Bertrand <[hidden email]> wrote:
> >
> > Hello,
> >
> > use the following method:
> >
> > set my_variable_ Appl_udp_$src_$flowid
> >
> > and when you want to refer to the content of this variable (what you
> > tried to do with Appl_udp_$src_$flowid) use the following code:
> >
> > [expr $$my_variable_]
> >
> > explanations: my_variable_ contains the name of your variable
> > (Appl_udp_$src_$flowid). So $my_variable_ is the name of your variable
> > (Appl_udp_$src_$flowid) and [expr $$my_variable_] refers to the contains
> >
> > of this variable (sort of $Appl_udp_$src_$flowid).
> >
> > I have not been clear, but I hope this helps.
> >
> >
> > Mit freundlichen Grüßen, with kind regards, cordialement,
> >
> > ----------------------------------------------------------------------
> >         Gilles BERTRAND
> > Institut National des Télécommunications (GET)- Universität Stuttgart
> > ----------------------------------------------------------------------
> >
> > Nicholas Loulloudes a écrit :
> > > 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.
> >
> >
> > --
> >
>
>
>
> --
> Nicholas Loulloudes
>
> Postgraduate at Communication Networks and Software.
>
> BSc in Computer Science.
>



--
Mit freundlichen Grüßen, with kind regards, cordialement,

----------------------------------------------------------
Gilles BERTRAND
Telecom INT - University of Stuttgart
----------------------------------------------------------