*sigh* The following code seems to work fine on my PC but I get an error message (one I haven't managed to come up with before) when I run it from my web site.
#!/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 if($sort eq "id" ){ @all_hashes = sort { $a->{ID} <=> $b->{ID} } @all_ +hashes;} if($sort eq "info" ){ @all_hashes = sort { $a->{info} <=> $b->{info} } + @all_hashes;} if($sort eq "graphics" ){ @all_hashes = sort { $a->{graphics} <=> $b-> +{graphics} } @all_hashes;} if($sort eq "friendly" ){ @all_hashes = sort { $a->{friendly} <=> $b-> +{friendly} } @all_hashes;} if($sort eq "techno" ){ @all_hashes = sort { $a->{techno} <=> $b->{tec +hno} } @all_hashes;} if($sort eq "entertain" ){ @all_hashes = sort { $a->{entertain} <=> $b +->{entertain} } @all_hashes;} if($sort eq "average" ){ @all_hashes = sort { $a->{rate} <=> $b->{rate +} } @all_hashes;} if($sort eq "hits" ){ @all_hashes = sort { $a->{hit} <=> $b->{hit} } @ +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>";
The error message is:
Click on a header to sort. ID Info Graphics Friendly Techno Entertain Average Hits Content-type: text/html Software error: Modification of a read-only value attempted at line 50. For help, please send mail to the webmaster (support@aplus.net), givin +g this error message and the time and date of the error.
Line 50 is if($sort eq "id" ){ @all_hashes = sort { $a->{ID} <=> $b->{ID} } @all_hashes;} What have I done (now)?

In reply to Error in code - read-only value? by katgirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.