In the files for your average computation, there's a subroutine called
sub compute_averages. There's a section that looks like this:
Code:
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; } # Skip and Remove blank lines
if ($line =~ /^#/) { $output .= $line; next LINE; } # Comment Line
chomp ($line);
@data = &split_decode($line);
if ($data[0] > 0) {
++$number_of_records;
for ($i = 0; $i<=5; $i++) {
$total[$i] += $data[$i];
}
}
}
if ($number_of_records > 0) {
for ($i = 0; $i<=5; $i++) {
$average[$i] = $total[$i] / $number_of_records;
$average[$i] = int($average[$i] + .5);
}
}
$output = join '|', @average;
This assumes that fields 0 through 5 contain numbers you want to average. Let's say that fields 6 through 9 contain the "Yes/No" answers that you want to find the percentages of. Add the following bolded code:
Code:
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; } # Skip and Remove blank lines
if ($line =~ /^#/) { $output .= $line; next LINE; } # Comment Line
chomp ($line);
@data = &split_decode($line);
if ($data[0] > 0) {
++$number_of_records;
for ($i = 0; $i<=5; $i++) {
$total[$i] += $data[$i];
}
for ($i=6; $i<=9; $$i++) {
if ($data[$i] eq "Yes") { $total[$i]++; }
} }
}
if ($number_of_records > 0) {
for ($i = 0; $i<=5; $i++) {
$average[$i] = $total[$i] / $number_of_records;
$average[$i] = int($average[$i] + .5);
}
for ($i=6; $i<=9; $$i++) {
$average[$i] = ($total[$i]/$number_of_records)*100;
$average[$i] = int($average[$i] + .5);
} }
$output = join '|', @average;
I think. :-)
When you load in your averages in html.pl, sub html_record, your percentages will be in $average[6] through $average[9]. You just need to print them out where you want them and add the
% sign.
If you're going to copy and paste the code, only copy the bolded sections and put them in the right spot. Otherwise you'll have problems because of the lack of carriage returns on the message board.
JPD
----------------------------------------------------
JPDeni's DBMan-ual How to
ask questions the smart way.