Gossamer Forum
Home : Products : DBMan : Customization :

Get total from total

Quote Reply
Get total from total
Hi,
What I have is the following working but would like to take it one step further.

open (DB, "<$db_file_name") or &cgierr("error in count. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB,1); }
@lines = <DB>;
close DB;
foreach $line (@lines) {
chomp ($line);
@data = &split_decode($line);
++$count{$data[4]}; # Week of the year
++$count{$data[7]}; # Planned Duration eg 4 hrs
$total8 += {$data[8]}; # Actual Duration eg 5 hrs
++$total_count;
}
This works fine and give a result like
31:1:0
32:1:0
33:2:0

What I'm trying to do is get the above to give the total value of $data[8]
31:1:4
32:1:5
33:2:10 # found two record for week 33 and the total value for $data[8] = 10 (5+5)

Hope this make sence in wait I'm try to achieve.
Quote Reply
Re: [colinw] Get total from total In reply to
I'm not sure I understand what you're doing, but I think you're trying to compute the number of hours that something happened during given weeks of the year. It appears that the number of the week is in Field 4 of your database and the number of hours are in Field 8. So, to total the actual number of hours per week, instead of

$total8 += {$data[8]};

you would want to use

$actual{$data[4]} += $data[8];

I'm not sure of the use of

++$count{$data[7]}; # Planned Duration eg 4 hrs

If you wanted the planned duration per week, you would want to accumulate that in much the same way, assuming the number of planned hours is in field 7 in your database:

$planned{$data[4]} += $data[7];

To print it out, you would use something like:

Code:

for ($i = 1; $i<=52; ++$i) {
print qq|$i : $count{$i} : $planned{$i} : $actual{$i}<BR>|;
}


This will give you a line for each week of the year with the information --
week number : number of instances in the week : number of planned hours for the week : number of actual hours for the week


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.