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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to make sense of "array get arr" output response

Status
Not open for further replies.

LilTCLer

Programmer
Nov 27, 2007
37
US
I'm trying to make sense out of the "array get" output:

This is my array:
portHandleArray(0): 1
portHandleArray(1): 2
portHandleArray(2): 3
portHandleArray(3): 4
portHandleArray(4): 11
portHandleArray(5): 12
portHandleArray(6): 13
portHandleArray(7): 14

tclsh>array get portHandleArray
4 11 0 1 5 12 1 2 6 13 2 3 7 14 3 4

I guess I would have assumed that the output would look like the following:

0 1 1 2 2 3 3 4 4 11 5 12 6 13 7 14

where each odd numbered element is the index, and the even is the value. Can someone explain why I am seeing the output I am seeing?

TIA
 
the "array get" function is not ordered. The "key-value" pairs are simply presented as "complete" but in no particular order. So, for instance, as long as 0 is paired with 1 and 4 is paired with 11, wherever they occur in the list is valid and, more importantly, correctly interpreted by "array set".

_________________
Bob Rashkin
 
So is there anyway to return them where each odd numbered element is the index, and the even is the value?
 
I'm not sure what you mean. In the example you posted, array get returned:
4 11 0 1 5 12 1 2 6 13 2 3 7 14 3 4

That means that the array indices: 4,0,5,1,6,2,7,3 correspond to array values: 11,1,12,2,13,3,14,4

That is, they already alternate: index, value, index, value,...
They're just not in any order. Remember that arrays in Tcl are hash tables. Just because you've indexed the array numerically, to Tcl those indices are still strings. They might just as well be "zero, one, two,..." as "0, 1, 2,..."

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top