I'm very new to Perl and I modified a poll script in Perl. Everything works great so far. The only thing I would like to change is the poll results should be sorted according to votes. The variable for this is $votes. I would like to have the answers with most votes at top.
Can anyone help me please how to modify the code below which is responsible for the output of the poll results?
Cordially,
Baris
Can anyone help me please how to modify the code below which is responsible for the output of the poll results?
Cordially,
Baris
Code:
sub results {
foreach $line(@data) {
($topic, $num, $others) = split(/\|/, $line);
if ($num eq $FORM{'topic'}) { last }
}
print "<html><head><title>$topic :: Results</title></head>\n";
print "<body bgcolor=\"#$bkgdc\" TEXT=\"#$textc\" link=\"#$linkc\" vlink=\"#$vlinkc\">\n";
&sig;
print "<h1><font color=\"#ffffff\">$topic</font></h1>\n";
print "<center><table bgcolor=\"#333333\" width=\"700\" border=\"0\"><tr><td>\n";
print "<table width=100% cols=\"5\"><tr>";
print "<td width=\"25%\"> </td><td width=5% align=right ><b>Oy</b></td>\n";
print "<td width=10% align=right><b>%</b></td>\n";
print "<td width=3%> </td><td width=60%>\n";
print "<center><b>Cevap</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><b><font color=\"#ffffff\" size=\"3\">$votes</font></b></i></td>";
print "<td width=5% align=right><i><font size=\"2\">$percent</font></i></td>";
print "<td width=3%> </td>\n";
print "<td width=60%><font size=\"2\">$topic</font></td></tr>\n";
}
print "</table><center><form method=\"POST\"><input type=\"submit\" value=\" Anasayfaya Geri\">\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></html>\n";
exit;
}