karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sliding window revisited: Is it OK to make it so?
by choroba (Cardinal) on Jul 19, 2019 at 21:36 UTC | |
by karlgoethebier (Abbot) on Jul 20, 2019 at 08:51 UTC | |
|
Re: Sliding window revisited: Is it OK to make it so?
by LanX (Saint) on Jul 19, 2019 at 22:11 UTC | |
by karlgoethebier (Abbot) on Jul 20, 2019 at 09:09 UTC | |
by LanX (Saint) on Jul 20, 2019 at 09:45 UTC | |
|
Re: Sliding window revisited: Is it OK to make it so?
by hippo (Archbishop) on Jul 20, 2019 at 09:04 UTC | |
by karlgoethebier (Abbot) on Jul 20, 2019 at 09:27 UTC | |
|
Re: Sliding window revisited: Is it OK to make it so?
by LanX (Saint) on Jul 20, 2019 at 15:31 UTC |