in reply to Re^2: Looping Over Hash Skips an Element?
in thread Looping Over Hash Skips an Element?
if ($counter <= 8) { $sum_values[$x] += $ifSpeeds{ $key }; $counter++; } else { $x++; $sum_values[$x] = $ifSpeeds{ $key }; $counter = 1; }
To avoid the almost-duplication of the key statement, you could also write
$sum_values[$x] += $ifSpeeds{ $key }; $x++ unless ++$counter % 8;
or even simply
$sum_values[$counter++/8] += $ifSpeeds{ $key }; # the [] impli +es int(...)
(Perl does not generate a warning when you do something like $sum += ..., with $sum being undef initially — it treats it as 0)
|
|---|