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

Sorting a flatfile (Windows)

Status
Not open for further replies.

klibby

Programmer
May 30, 2001
51
0
0
US
OK.. I'm writing kind of a quiz thing and want to display a top ten scores list out of a flatfile database with all the scores... I've seen a bunch of examples of this, though all for Unix..

I want to sort with the first field... from highest to lowest scores so I can pull the first 10 lines for high scores... (I tried using system("sort......").. but realized if you have 9 and 10.. it will put 9 first and 10 second since 9 > 1....


I want it to go from looking like....

1|Kyle
50|Bob
25|Joe
100|MAtt

to

100|Matt
50|Bob
25|Joe
1|Kyle


Thanks for your help


 
klibby,

This should do the trick:
[tt]
my @array = ("1|Kyle","50|Bob","25|Joe","100|MAtt");

@array = reverse sort { (split(/\|/,$a))[0] <=> (split(/\|/,$b))[0]; } @array;

print join(&quot;\n&quot;,@array);
[/tt]



AD AUGUSTA PER ANGUSTA

Thierry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top