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

lsort

Status
Not open for further replies.

Thodd

Technical User
Oct 21, 2006
27
BE
Hello,

I have a list that I want to sort, but I can't get it right.
The pckt-array has a timestamp and a value on each line and is sorted by the timestamp.

set pcktlst ""
foreach {name value} [array get pckt] {
lappend pcktlst $name $value
}
set pcktlst [lsort -integer -index 0 $pcktlst]
#now the $name should be deleted out of the list so that only the values remain.

So I'd like to have a pcktlst with only the values, in the same order they appear in the pckt-array.
How can I get that?

thx
 
I'm not sure I follow but I think you need a list of lists to do the sort you want. That is, set pcktlst [lsort -integer -index 0 $pcktlst] is sorting the list on the 0th element of the elements of that list. That is, in your case, your list would have to be of the form: {{time value} {time value} ...}. What about this:
Code:
foreach {name value} [array get pckt] { 
lappend pcktlst [red]"[/red]$name $value[red]"[/red]
}
set pcktlst [lsort -integer -index 0 $pcktlst]
#now the $name should be deleted out of the list so that only the values remain:
foreach pair $pcktlst {lappend valList [lindex $pair 1]}

_________________
Bob Rashkin
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top