in reply to Refactor this to eliminate the duplicated printf?
Hello there,
davido has already provided you the answer. Why not use it?
use 5.014; use warnings; use strict; my ($sum, $count) = (0,0); while (<DATA>) { $sum += $_; $count++; if ($count == 5 || eof(\*DATA)) { printf "Sum: %4d, count: %2d, mean: %5.1f\n", $sum, $count, $sum/$count; $sum = 0; $count = 0; } } __DATA__ 61 23 30 444 368 438 467 44 812 430 992 469 123
PS: I don't see u thank him so i thought you didn't understand his answer :))
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Refactor this to eliminate the duplicated printf?
by wanna_code_perl (Friar) on Jul 14, 2014 at 06:59 UTC |