Prev: "HUH???" and/or "wiki broken, VERY broken?" was [Re: Plotting 3D surfaces]
Next: "HUH???" and/or "wiki broken, VERY broken?" was [Re: Plotting3D surfaces]
From: Keith on 10 Apr 2010 22:04 I have an array with multiple entries and I am wondering what would be the correct & best way to sort them. $foo(arr,1)...$foo(arr,99) Is there a way to use lsort on all the different items in the array? -- Best Regards, Keith http://home.comcast.net/~kilowattradio/ I'm Your Huckle Berry http://www.youtube.com/watch?v=KfbAFgD2mLo
From: Gerald W. Lester on 11 Apr 2010 22:34 Keith wrote: > > > I have an array with multiple entries and I am wondering what would be > the correct & best way to sort them. > > $foo(arr,1)...$foo(arr,99) > > Is there a way to use lsort on all the different items in the array? What do you want sorted the keys or the values? -- +------------------------------------------------------------------------+ | Gerald W. Lester | |"The man who fights for his ideals is the man who is alive." - Cervantes| +------------------------------------------------------------------------+
From: Keith on 11 Apr 2010 23:23 On Sun, 11 Apr 2010 21:34:58 -0500, "Gerald W. Lester" <Gerald.Lester(a)cox.net> wrote: >Keith wrote: >> >> >> I have an array with multiple entries and I am wondering what would be >> the correct & best way to sort them. >> >> $foo(arr,1)...$foo(arr,99) >> >> Is there a way to use lsort on all the different items in the array? > >What do you want sorted the keys or the values? I want to sort the values in the arrays. $foo(arr,1) = "C wordone" $foo(arr,2) = "A wordone"
From: tom.rmadilo on 11 Apr 2010 23:52 On Apr 11, 8:23 pm, Keith <kilowattra...(a)use-reply-to.invalid> wrote: > On Sun, 11 Apr 2010 21:34:58 -0500, "Gerald W. Lester" > > <Gerald.Les...(a)cox.net> wrote: > >Keith wrote: > > >> I have an array with multiple entries and I am wondering what would be > >> the correct & best way to sort them. > > >> $foo(arr,1)...$foo(arr,99) > > >> Is there a way to use lsort on all the different items in the array? > > >What do you want sorted the keys or the values? > > I want to sort the values in the arrays. > > $foo(arr,1) = "C wordone" > $foo(arr,2) = "A wordone" I assume once you sort, you end up with a list. So ditch the array and use a list to begin with like this: % set mylist {{arr,1 "C wordone"} {arr,2 "A wordone"}} then use [lsort] % lsort -index 1 $mylist {arr,2 "A wordone"} {arr,1 "C wordone"}
From: Glenn Jackman on 12 Apr 2010 01:33
At 2010-04-11 11:52PM, "tom.rmadilo" wrote: > On Apr 11, 8:23�pm, Keith <kilowattra...(a)use-reply-to.invalid> wrote: [...] > > �I want to sort the values in the arrays. > > > > $foo(arr,1) = "C wordone" > > $foo(arr,2) = "A wordone" > > I assume once you sort, you end up with a list. So ditch the array and > use a list to begin with like this: > > % set mylist {{arr,1 "C wordone"} {arr,2 "A wordone"}} Well, you don't have to ditch the array: set mylist [list] foreach {key value} [array get foo] { lappend mylist [list $key $value] } > then use [lsort] > > % lsort -index 1 $mylist > {arr,2 "A wordone"} {arr,1 "C wordone"} If you have Tcl 8.6, you can achieve the same kind of thing quicker: array set foo {arr,1 "C wordone" arr,2 "A wordone"} lsort -stride 2 -index 1 [array get foo] # ==> arr,2 {A wordone} arr,1 {C wordone} -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous |