It's harder than that. Consider what happens if you have data that is trending down, but where the steps are well within the 0.5 criteria:
use strict; use warnings; my $delta = .5; my ($avg, $sum, $i); while (<DATA>) { $i++; my @cols = split; if ($i == 1) { $avg = $cols[3]; $sum = $avg; next; } if (abs($cols[3] - $avg) > $delta) { print "Warning, Will Robinson: $_"; $i--; next; } $sum += $cols[3]; $avg = $sum / $i; } __DATA__ A15 26.62 765 27.30 4.3 A11 26.63 763 27.28 4.2 A12 26.68 767 27.1 4.3 A16 26.64 768 27.0 4.2 A11 26.62 761 26.8 4.1 A15 26.62 765 26.6 4.3 A15 26.63 763 26.3 4.2 A16 26.68 767 26.0 4.3 A17 26.64 768 25.7 4.2 A18 26.62 761 25.4 4.1
Prints:
Warning, Will Robinson: A15 26.63 763 26.3 4.2 Warning, Will Robinson: A16 26.68 767 26.0 4.3 Warning, Will Robinson: A17 26.64 768 25.7 4.2 Warning, Will Robinson: A18 26.62 761 25.4 4.1
In reply to Re^2: comparing numbers from previous lines in a file?
by GrandFather
in thread comparing numbers from previous lines in a file?
by coding1227
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |