Re: Variable naming




Dario D. wrote:
Hello all,

Is slash (/) allowed in variable names? I'm reading a tutorial on the
NS2 simulator, and it appears to be using slashes in class names:

set tcp [new Agent/TCP]

I tried to run the following example through tclsh, but as you can see
it didn't work out well:

% set test/blah 5
5
% puts $test/blah
can't read "test": no such variable


Yes / is allowed in variable names. However, you do have to take a bit
care when getting the value with $. Not all the values that are valid
in a variable name, are valid in a $ expansion without braces. For the
exact rules see the Dodekalogue (http://wiki.tcl.tk/10259) rule 8.

For an example of how to get the value see the following session:
% set a/b test
test
% puts $a/b
can't read "a": no such variable
% set a/b
test
% puts ${a/b}
test

Mark

.