This is something it i would like to share because the technique was so often mentioned on PM and never really explained as far as i can remember.

By chance i stumbled over List::Gen which provides slide {CODE} WINDOW LIST.

Unfortunately the module doesn't compile on my system/with my Perl version.

But it seems to be quite easy to steal some code from it that seems to work like a charm:

#!/usr/bin/env perl use strict; use warnings; use List::Util::PP qw(min reduce); use feature qw(say); sub slide (&$@); say slide {qq(@_\n)} 2 => 1 .. 4; say slide {uc qq(@_\n)} 2 => qw(nose cuke foo bar); sub slide (&$@) { my ($code, $window) = splice @_, 0, 2; $window--; map $code->(@_[$_ .. min $_+$window, $#_]) => 0 .. $#_; } __END__ Karls-Mac-mini:Desktop karl$ 1 2 2 3 3 4 4 NOSE CUKE CUKE FOO FOO BAR BAR

To me this looks like it works as designed and expected.

Thanks for any hint and comment. Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help


In reply to Sliding window revisited: Is it OK to make it so? by karlgoethebier

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.