# Read each line of file supposing a number per line # while <FILE> { # # the += operator will add each number read to #the accumulated # $total += $_; # # $_ contains the line just read of FILE # ++ will increment 1 for each line giving a total # count of lines at the end of the loop # $count++; } # # at the end of the loop you have total = sum of lines # and count how many lines where read # my $average = $total/$count; # # the formula above calculates the average
Now Can you see the code? Any line that starts with # is a comment.
In reply to Re: Beginner question - understanind a loop with a file handle
by Generoso
in thread Beginner question - understanind a loop with a file handle
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |