Here is one possible way:
You can use 'perldoc -f glob' or shell commands to redirect all the input data to stdin.use strict; my $n = 2; my $cnt; my $sum; while(<>) { chomp; $cnt++; my (undef, $v) = split(/\|/); $sum += $v; print "cnt: $cnt v: $v sum: $sum\n"; if (($cnt % $n) == 0) { print "avg: " . $sum / $n . "\n";; $sum = 0 ; } }
In reply to Re: take 'n' array elements at a time
by pme
in thread take 'n' array elements at a time
by fionbarr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |