I would stick with the while loop as it is more scalable and make use of List::Util.
use warnings; use strict; use List::Util qw(max); my @window; while (<DATA>) { chomp(); # create sliding window push(@window, [ (split) ]); shift(@window) if $. > 5; # print range print $window[0][0], "-", $window[-1][0]; # print maximums for my $i (1 .. 5) { print " ", max(map { $_->[$i] } @window); } print "\n"; } __END__ 1 0 0.00 0 0 0 2 0 0.00 0 0 0 3 0 0.08 0 0 0 4 0 0.05 0 0 0 5 0 0.08 0 0 0 6 0 0.05 0 0.12 0 7 0 0.05 0 0.12 0 8 0 0.04 0 0.15 0 9 0.07 0.07 0 0.15 0.18 10 0.29 0.04 0.32 0.32 0.19 11 0.46 0.05 0.42 0.30 0.21 12 0.45 0.07 0.35 0.29 0.41 13 0.57 0.07 0.42 0.00 0.47 14 0.46 0.04 0.62 0.00 0.58 15 0.39 0.05 0.41 0.00 0.37

Output:
1-1 0 0.00 0 0 0 1-2 0 0.00 0 0 0 1-3 0 0.08 0 0 0 1-4 0 0.08 0 0 0 1-5 0 0.08 0 0 0 2-6 0 0.08 0 0.12 0 3-7 0 0.08 0 0.12 0 4-8 0 0.08 0 0.15 0 5-9 0.07 0.08 0 0.15 0.18 6-10 0.29 0.07 0.32 0.32 0.19 7-11 0.46 0.07 0.42 0.32 0.21 8-12 0.46 0.07 0.42 0.32 0.41 9-13 0.57 0.07 0.42 0.32 0.47 10-14 0.57 0.07 0.62 0.32 0.58 11-15 0.57 0.07 0.62 0.30 0.58

In reply to Re: creating and printing a sliding window by repellent
in thread creating and printing a sliding window by Angharad

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.