I have a subroutine that opens a text file, which contains 50 or so lines, sorts them, and then leaves only the top 10. The code is below. Here is how my text file is setup (that gets sorted):
Name|Email|score
What the code does is it sorts the file by score, decending, and then only saves the top 10 records, by score.
PROBLEM: If multiple people have the same score, it won't include them all. It is only thinking the scores are unique. How can I modify the code so that it will sort but include people with ununique scores?
Thanks for any assistance!
Name|Email|score
What the code does is it sorts the file by score, decending, and then only saves the top 10 records, by score.
PROBLEM: If multiple people have the same score, it won't include them all. It is only thinking the scores are unique. How can I modify the code so that it will sort but include people with ununique scores?
Thanks for any assistance!
code:<HR>Code:print "Content-type: text/html\n\n"; <P>use strict; open(IN,"</usr/www/users/me/file.txt") or die $!; chomp(my @lines = <IN> ); close IN; my %cds; foreach(@lines){ my @a = split /\|/; $cds{$a[2]} = [ @a[0,1] ]; } open(OUT,">/usr/www/users/me/file.txt") or die $!; my $c = 0; foreach(sort {$b <=> $a} keys %cds){ print OUT join('|',@{$cds{$_}},$_) . "\n"; $c++; last if $c == 10; } close OUT;