#!/usr/bin/perl -lw use strict; use constant WINDOW => 30; my $sum = 0; my $n = 0; my $p = WINDOW; while () { my ($pos, $val) = split; if (eof) { # corner case $sum += $val; $n++; } if ($pos > $p or eof) { print $sum / $n if $n > 0; $sum = 0; $n = 0; $p += WINDOW while $pos > $p; } $sum += $val; $n++; } __DATA__ 1 1 10 3 30 1 40 2 60 2 #### 1.66666666666667 2