0

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.

James
  • 4,644
  • 5
  • 37
  • 48

1 Answers1

0

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

Peter Lewerin
  • 13,140
  • 1
  • 24
  • 27