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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |