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
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.