in reply to Re: comparing numbers from previous lines in a file?
in thread comparing numbers from previous lines in a file?

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
True laziness is hard work

Replies are listed 'Best First'.
Re^3: comparing numbers from previous lines in a file?
by Kenosis (Priest) on Nov 22, 2013 at 02:50 UTC

    Yes, good point. Had wondered whether I'd oversimplified the issue...

    Edit: On second thought, it might not be "harder than that". The OP did say, "all of which are approx. 27.3 degrees Celsius", so it depends solely upon the OP's data set. There may never be an instance of such a downtrending of values--especially the way the OP characterized the data.