Gossamer Forum
Quote Reply
Sort
Hi if i have the following sub

sub get_average {
# --------------------------------------------------------
# Get the "average" value of a field.
#

my $which_id = shift;
my $id_pos = 0;
my $rating_pos = 22;
my $which_db = $db_script_path . "/rating.db";
my $avg_count = 0; # Initialise the counter
my $avg_total = 0; # Initialise the total

open (DB, "<$which_db") or &cgierr("Unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;

foreach $line (@lines) {
chomp ($line);
@tmp_record = split (/\Q$db_delim\E/o, $line);
if ($tmp_record[$id_pos] eq $which_id) {
$avg_count++; # Count up each record
$avg_total = $avg_total + $tmp_record[$rating_pos]; # Add rating to total
}
}
if ($avg_count > 0) {

$avg_total = int $avg_total / $avg_count; # Average the total by number of records
} else { $avg_total = 'Player not yet rated'; }

print $avg_total;

}

How could I sort on this sub if my short display looks like this.


<font size="-4"><A HREF="$db_script_link_url&ww=on&sb=$avg_total&$db_key=$rec{$db_key}&view_records=1">$rec{'Lastname'}</A></font></TD>
<td valign=top><font size="-4">$rec{'Firstname'}</font></td>
<td valign=top><font size="-4">$rec{'Team'}</font></td>
<td valign=top><font size="-4">$rec{'Month'}/$rec{'Day'}/$rec{'Year'}</font></td>
<td valign=top><font size="-4">|;&get_average("$rec2{'Playerid'}");print qq|</font></td>


I want to sort on the get average subroutine. Will pay for a solution to this