Polyglot has asked for the wisdom of the Perl Monks concerning the following question:
I'm pushing a large number of items into an array that is later converted into columns in LaTeX. LaTeX puts the items in order, vertically, spilling over into the next column after each column is filled. I need the items to be placed across the page in rows, instead of vertically. Owing to code that allows the column count to be adjustable, I cannot predict how many columns there will be, but I can use the user-variable for the column count to help transform the array. It seems like something like 'map' should be able to do this efficiently, but I have no idea how.
I could do this by brute force, of course, creating a separate array for each column, then shifting off the original array and shuffling to each column's array, then pushing them all into a single array again. But that just doesn't seem like the Perl way to do things. I couldn't find anything about this here or via Google--but it seems someone might have wanted to transform an array like this before. Your wisdom is welcome.
Essentially, I would like to convert something like this:
| One | Five | Nine | Thirteen |
| Two | Six | Ten | Fourteen |
| Three | Seven | Eleven | Fifteen |
| Four | Eight | Twelve | Sixteen |
Into something like this:
| One | Two | Three | Four |
| Five | Six | Seven | Eight |
| Nine | Ten | Eleven | Twelve |
| Thirteen | Fourteen | Fifteen | Sixteen |
Look like fun?
Blessings,
~Polyglot~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to warp an array by trading X/Y coordinates (rows/columns)
by choroba (Cardinal) on Mar 08, 2016 at 15:51 UTC | |
|
Re: How to warp an array by trading X/Y coordinates (rows/columns)
by BrowserUk (Patriarch) on Mar 08, 2016 at 15:39 UTC | |
by Polyglot (Chaplain) on Mar 08, 2016 at 15:50 UTC | |
by BrowserUk (Patriarch) on Mar 08, 2016 at 15:56 UTC | |
|
Re: How to warp an array by trading X/Y coordinates (rows/columns)
by toolic (Bishop) on Mar 08, 2016 at 15:35 UTC | |
|
Re: How to warp an array by trading X/Y coordinates (rows/columns)
by VinsWorldcom (Prior) on Mar 08, 2016 at 17:20 UTC | |
|
Re: How to warp an array by trading X/Y coordinates (rows/columns)
by Your Mother (Archbishop) on Mar 08, 2016 at 17:27 UTC | |
|
Re: How to warp an array by trading X/Y coordinates (rows/columns)
by jcb (Parson) on Mar 09, 2016 at 00:44 UTC |