in reply to Re: Error in code - read-only value?
in thread Error in code - read-only value?
But now it's sorting the keys in text order (1 - 100 - 101 - 2 - 21 etc) and when I click on the links to change the sorted by order, it still comes out sorted by ID.#!/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.<br>"; print "<table><tr><td><a href=\"?sort=ID\">ID</a></td>\n<td><a href=\" +?sort=info\">Info</a></td>\n<td><a href=\"?sort=graphics\">Graphics</ +a></td>\n<td><a href=\"?sort=friendly\">Friendly</a></td>\n<td><a hre +f=\"?sort=techno\">Techno</a></td>\n<td><a href=\"?sort=entertain\">E +ntertain</a></td>\n<td><a href=\"?sort=average\">Average</a></td>\n<t +d><a href=\"?sort=hits\">Hits</a></td>\n</tr>"; 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 = <TXTFILE>; 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 + $frien +dly + $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 "<tr><td>$_->{ID}</td>\n<td>$_->{info}</td>\n<td>$_->{graph +ics}</td>\n<td>$_->{friendly}</td>\n<td>$_->{techno}</td>\n<td>$_->{e +ntertain}</td>\n<td>$_->{rate}</td>\n<td>$_->{hit}</td>\n</tr>"; } print "</table>"; sub sortby { my $key = shift; my $aref = shift; sort { $a->{$key} <=> $b->{$key} } @$aref; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Error in code - read-only value?
by Mr. Muskrat (Canon) on Sep 23, 2003 at 14:17 UTC |