spandox has asked for the wisdom of the Perl Monks concerning the following question:
What it does: Give it an array and a length - and it returns and array of arrays where each sub array is length long.sub doubleStack { my $count = pop; my @out; while (@_){push @out, [splice @_,0,$count];} return @out; }
It would be fun to be able to do this in-line without a sub. BTW - I use this for generating multi-line output - tables and such. Anyone have a cool way to do this?doubleStack(qw(a b c e 1 2 3 4 5 3 f),3) returns: $VAR1 = [ [ 'a', 'b', 'c' ], [ 'e', '1', '2' ], [ '3', '4', '5' ], [ '3', 'f'] ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: stack array to array of arrays
by Kenosis (Priest) on Oct 16, 2013 at 19:20 UTC | |
|
Re: stack array to array of arrays
by johngg (Canon) on Oct 16, 2013 at 21:54 UTC | |
|
Re: stack array to array of arrays
by hdb (Monsignor) on Oct 16, 2013 at 18:55 UTC | |
by spandox (Novice) on Oct 17, 2013 at 13:44 UTC | |
|
Re: stack array to array of arrays
by kcott (Archbishop) on Oct 17, 2013 at 04:24 UTC | |
|
Re: stack array to array of arrays
by LanX (Saint) on Oct 16, 2013 at 22:12 UTC | |
by spandox (Novice) on Oct 17, 2013 at 14:18 UTC | |
by LanX (Saint) on Oct 17, 2013 at 15:17 UTC | |
by spandox (Novice) on Oct 17, 2013 at 17:43 UTC | |
by LanX (Saint) on Oct 17, 2013 at 17:57 UTC | |
|
Re: stack array to array of arrays
by roboticus (Chancellor) on Oct 17, 2013 at 12:14 UTC | |
|
Re: stack array to array of arrays
by Random_Walk (Prior) on Oct 17, 2013 at 13:25 UTC |