#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser);
use CGI;
my $req = new CGI;
my $sort = $req->param("sort");
if(!$sort){ $sort = "ID";}
print "Content-type: text/html\n\n";
print "Click on a header to sort.
";
print "
ID | \nInfo | \nGraphics | \nFriendly | \nTechno | \nEntertain | \nAverage | \nHits | \n
";
opendir(DIR, "members");
my @files = grep( /\.dat/, readdir(DIR) );
@files = sort(@files);
closedir(DIR);
$num = 0;
foreach $file(@files){
open (TXTFILE, "members/$file") or die "Can't open $file";
@lines = ;
close(TXTFILE);
tr/\r\n//d for @lines;
$hit = $lines[0];
if($hit >0){
$info = sprintf("%.2f", ($lines[1]/$hit) );
$graphics = sprintf("%.2f", ($lines[2]/$hit) );
$friendly = sprintf("%.2f", ($lines[3]/$hit) );
$techno = sprintf("%.2f", ($lines[4]/$hit) );
$entertain = sprintf("%.2f", ($lines[5]/$hit) );
$rate = sprintf("%.2f", (($info + $graphics + $friendly + $techno + $entertain)/5) );
$id = $file;
$id =~ s/\.dat//;
$all_hashes[$num] = ({
ID => $id,
info => $info,
graphics => $graphics,
friendly => $friendly,
techno => $techno,
entertain => $entertain,
rate => $rate,
hit => $hit,
});
}#end if hit
$num++;
}#end for each file
sortby($sort, \@all_hashes);
for(@all_hashes){
print "$_->{ID} | \n$_->{info} | \n$_->{graphics} | \n$_->{friendly} | \n$_->{techno} | \n$_->{entertain} | \n$_->{rate} | \n$_->{hit} | \n
";
}
print "
";
sub sortby {
my $key = shift;
my $aref = shift;
sort { $a->{$key} <=> $b->{$key} } @$aref;
}