how to copy the variable into one dimesional array in tcl

821 views Asked by At

How do I set the single variable data into a one dimensional array in ns2 using Tool Command Language?
I have tried by using the set command for that variable and an array but it shows an error like variable not an array.

1

There are 1 answers

0
Peter Lewerin On BEST ANSWER

You need to study the Tcl documentation a bit more.

For variables, assignment looks like this:

set foo 99

(set name value)

For arrays, assignment looks either like this:

set bar(foo) 99

(set array-name(member-name) value)

or

array set bar {foo 99}

(array set array-namelist of member-names and values›)

You can't mix assignment modes. If abc is the name of an array and def is the name of a variable, the wrong mode of assignment will give you these errors:

% set abc 99
can't set "abc": variable is array

% set def foo 99
wrong # args: should be "set varName ?newValue?"

% set def(foo) 99
can't set "def(foo)": variable isn't array

You need to keep your variables and your arrays separate and use the correct invocations at all times.

Documentation: array