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