What if you kept a running average of col4 and compared the delta to that average minus the current value of col4?
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.29 4.3 A16 26.64 768 27.30 4.2 A11 26.62 761 27.31 4.1 A15 26.62 765 27.30 4.3 A15 26.63 763 27.28 4.2 A16 26.68 767 2.29 4.3 A17 26.64 768 27.30 4.2 A18 26.62 761 27.31 4.1
Output:
Warning, Will Robinson: A16 26.68 767 2.29 4.3
Hope this helps!
In reply to Re: comparing numbers from previous lines in a file?
by Kenosis
in thread comparing numbers from previous lines in a file?
by coding1227
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |