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.

Sort database

Help for those learning Tcl or writing their own scripts.
Post Reply
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Sort database

Post by oxygen »

Hello all.

I need some help to sort my database.
My database is formatted like this:
A1,B1,C1,D1 A2,B2,C2,D2 A3,B3,C3,D3 and so on...
Example:
345,nick1,23,56 333,nick2,22,3 200,nick3,4,3
I sort this with:

Code: Select all

set score [lsort -dict -decreasing [split [gets $scorefile]]]
but I want to sort B1 and B2 and B3 or C1 and C2 and C3 to.
How can I sort it that way.
Hope I explained it that somebody can understand it ;)

Tnx,
~oxygen
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Since you have the -decreasing switch, c3 will come before c2 c1 b3...etc (that's because tha ASCII representation of c is greater than b) so if you remove that switch, the order of the letters will become increasing (from a to z) but the numbers will probably come first (also from least to greatest).
o
oxygen
Voice
Posts: 22
Joined: Mon Sep 05, 2005 2:22 pm
Location: Germany

Post by oxygen »

Hello

I'll try to explaine it better. The database is part of a trivia game.
The first item is the yearly score, third item monthly score and so on.
With the above code the database is sorted by the first item, the yearly score. When I do a top 10 then it counts the yearly score. What I want is a top 10 score with the third item, the monthly score. How can I sort the database to do this?

Regards,
~oxygen
Z
ZeRoMe
Voice
Posts: 2
Joined: Mon May 01, 2006 5:40 am
Location: France

Post by ZeRoMe »

To sort correctly your score you must place item in first place, for exemple:
345,nick1,23,56
To order by item 4 (56) place this in first position:
56,345,nick1,23
Use split and lindex commands.
Post Reply