Greetings Perl Monks! I'm working on a rather simple script, but one small part keeps giving me trouble. It is supposed to give an average, but skip nonexistant entries. Maybe I can explain better with the actual code:
for (my $num = $members) {
foreach $month2 (@calendar) {
foreach $name2 (@members) {
if ($hoursWorked{$name2}{$month2} == 0) {
$num--; #this is to protect against false averages, because $members w
+ill usually have a value of 13, but I don't want to count the zero va
+lues because is would result in an incorrect average, (i.e. 24/6 inst
+ead of 24/13 because only 6 people worked)
$avg{$month2} += $hoursWorked{$name2}{$month2};
}
}
if ($num == 0) {
$avg{$month2} = 0;
}
else {
$avg{$month2} = $avg{$month2}/$num;
}
}
}
Right now, the problem is that it prints the incorrect averages, like 0 instead of 12. I'm sorry if I couldn't explain well, I barely understand what's going on myself. Anyone have any suggestions?
Just Another Perl Wannabe