I have the following code for showing the poll results. But I would like to sort the output according to $votes. Can anyone help me how to change this code?
sub results {
foreach $line(@) {
($topic, $num, $others) = split(/|/, $line);
if ($num eq $FORM{'topic'}) { last }
}
print "<head><title>$topic :: Results</title></head>\n";
print "<body bgcolor=\"#$bkgdc\" TEXT=\"#$textc\" link=\"#$linkc\" vlink=\"#$vlinkc\">\n";
&sig;
print "<h1>$topic</h1>\n";
print "<center><table width=\"500\" border=\"5\"><tr><td>\n";
print "<table width=100% cols=\"4\"><tr>";
print "<td width=\"25%\"> </td><td width=5%><center><b>Votes</b></td>\n";
print "<td width=10%><center><b>%</b></center></td><td width=60%>\n";
print "<center><b>Choice</b></center></td></tr>\n";
open (FILE, "$data_path/ch$FORM{'topic'}.txt");
@lines = <FILE>;
close(FILE);
$i = 0;
$maxvote=0;
foreach $line(@lines) {
($topic,$votes,$num) = split(/|/, $line);
$i = $i + $votes;
if ($votes>$maxvote) {$maxvote=$votes}
}
foreach $line(@lines) {
($topic,$votes,$num) = split(/|/, $line);
if ($i > 0) {
$percent = sprintf("%.2f",100 ($votes / $i));
$wide=int(100 $votes / $maxvote);
$wideetc=100- $wide;
}
else { $percent = "NA"; }
print "<tr>";
if($votes == 0) {
print "<td width=25%> </td>";
}
else {
print "<td width=25% align=right><i><img src=\"$colorbar\" BORDER=0 HEIGHT=12 WIDTH=$wide%></i></td>";
print "\n<TD width=25%><table width=100% border=0><tr>";
print "<td width=$widerem% bgcolor=#$bkgdc> </td>";
print "<td width=$wide% bgcolor=#$linkc> </td>";
print "</tr></table></td>";
}
print "<td width=5% align=right><i>$votes</i></td>";
print "<td width=10% align=right><i>$percent</i></td>";
print "<td width=60%><i><b>$topic</b></i></td></tr>\n";
}
print "</table><center><form method=\"POST\"><input type=\"submit\" value=\" Back to Main \">\n";
print "<input type=\"hidden\" name=\"pagename\" value=\"$pagename\">\n";
print "<input type=\"hidden\" name=\"userdir\" value=\"$userdir\">\n";
print "</form></center></td></tr></table></center>\n";
&sig;
print "</body>\n";
exit;
}