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

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.