This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

lsort - need two-pass sort :O

Help for those learning Tcl or writing their own scripts.
Post Reply
F
FallFromGrace
Voice
Posts: 17
Joined: Mon Jul 28, 2008 8:52 am

lsort - need two-pass sort :O

Post by FallFromGrace »

i have a list with such elements:
{kelly 15 1}
{john 50 4}
{jack 80 2}
{bill 70 3}
{ann 30 2}
{james 100 1}

so i need to sort it, to get:
{john 50 4}
{bill 70 3}
{jack 80 2}
{ann 30 2}
{james 100 1}
{kelly 15 1}

with first sort by 3th value and second sort by 2th value..

maximum that i can get is a list sorted by 2th or 3th value... [lsort -index 1 or 2 -decreasing $list]

how to sort it again?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

lsort uses a merge-sort, and depending on the merge-algorithm, you might be able to get away with something like this:

Code: Select all

set newlist [lsort -index 2 -decreasing [lsort -index 1 -decreasing $list]]
NML_375
F
FallFromGrace
Voice
Posts: 17
Joined: Mon Jul 28, 2008 8:52 am

Post by FallFromGrace »

it works ^^

tnx you )
Post Reply