in reply to List into two-dimensional array
If @list doesn't have millions of entries, I'd just copy to a new @tmp array before prior to using your solution.
But in the sense of TIMTOWTDI and with the power of autovivification ... :)
(demo in debugger)
DB<260> @a= "a" .. "h" DB<261> @b=(); $i=0; $C=3 DB<262> push @{ $b[ $i++/$C ] } , $_ for @a DB<263> x @b 0 ARRAY(0x3d7e3b0) 0 'a' 1 'b' 2 'c' 1 ARRAY(0x3d81440) 0 'd' 1 'e' 2 'f' 2 ARRAY(0x3d8e7f8) 0 'g' 1 'h' DB<264> x @a 0 'a' 1 'b' 2 'c' 3 'd' 4 'e' 5 'f' 6 'g' 7 'h' DB<265>
HTH :)
NB: you haven't been clear about your row $R requirement.
it's a poor man's solution for hippo's part() solution in Re: List into two-dimensional array, but since List::MoreUtils isn't core and List::Util doesn't offer it ...
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: List into two-dimensional array
by LanX (Saint) on Dec 14, 2020 at 21:42 UTC |