UPDATE ... populate a look-back array with rows from the original data. ... The flow concept goes like this:
  run through the original data via foreach. For every original data row :
    while there are less than 15 rows in the look-back array, push each original data row onto the look-back array
    after there are 15 rows in the look-back array, scan the look-back array for the specified value,
    then shift the first row off of the look-back array and push the current original data row onto the look-back array
    repeat until the end of the original data

Is this flow concept so far off ...?

Actually, that seems like a nice approach — assuming you understand what's really in the rows you're dealing with!

Of course, there are always Other Ways To Do It. If the data in a typical row was very large (megabytes) and you really needed to maximize speed and so to minimize data movement, an approach based solely on array references and manipulation of array indices might be productive.

>perl -wMstrict -le "my @ra = (0, 1, 42, 3, 4, 5, 6, 7, 8, 42, 10, 42, 12, 42); ;; for my $i (0 .. $#ra) { look_back_5_for_42(\@ra, $i); } ;; sub look_back_5_for_42 { my ($ar, $current_i) = @_; ;; my $back = $current_i - 5 + 1; $back = 0 if $back < 0; ;; printf qq{at index $current_i: }; for my $i ($back .. $current_i) { printf qq{42 at index $i, } if $ar->[$i] == 42; } print ''; } " at index 0: at index 1: at index 2: 42 at index 2, at index 3: 42 at index 2, at index 4: 42 at index 2, at index 5: 42 at index 2, at index 6: 42 at index 2, at index 7: at index 8: at index 9: 42 at index 9, at index 10: 42 at index 9, at index 11: 42 at index 9, 42 at index 11, at index 12: 42 at index 9, 42 at index 11, at index 13: 42 at index 9, 42 at index 11, 42 at index 13,

In reply to Re: element of an array of arrays by AnomalousMonk
in thread element of an array of arrays by JockoHelios

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.