in reply to Re^4: Sub-setting an Array
in thread Sub-setting an Array
Like this?
Output:#!/usr/bin/perl use strict; use warnings; my @array = qw/ c h e a p s l i d i n g w i n d o w /; my $elements = @array; for ( my $offset = 0; $offset < $elements; $offset++ ) { for my $length ( 1 .. 3 ) { next if $length != 3 and $offset >= 1; my @to_splice = @array; my @spliced = splice @to_splice, $offset, $length; print "@spliced\n"; } } __END__
$ perl 1141079.pl c c h c h e h e a e a p a p s p s l s l i l i d i d i d i n i n g n g w g w i w i n i n d n d o d o w o w w $
Note that a "sliding window" is a Thing and if you do some research you'll probably find existing tools for implementing it in your program.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Sub-setting an Array
by Anonymous Monk on Sep 05, 2015 at 01:17 UTC | |
by 1nickt (Canon) on Sep 05, 2015 at 01:27 UTC | |
by kgherman (Novice) on Sep 05, 2015 at 01:33 UTC | |
by Anonymous Monk on Sep 05, 2015 at 02:27 UTC |