in reply to stack array to array of arrays
This works but it is not cool...
use strict; use warnings; use Data::Dumper; my @array = qw(a b c e 1 2 3 4 5 3 f); my $len = 3; my @stack = map{$_%$len?():[grep{$_}@array[$_..$_+$len-1]]} 0..@array- +1; print Dumper \@stack;
...or this...a destructive version...
@array = map { [ map { shift @array//() } 1..$len ] } 0..int((@array-1)/$len);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: stack array to array of arrays
by spandox (Novice) on Oct 17, 2013 at 13:44 UTC |