in reply to How to warp an array by trading X/Y coordinates (rows/columns)

Like this?:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @data = map[ split ' ' ], <DATA>; pp \@data; my @xformed; push @xformed, [ map shift @$_ // (), @data ] while @{ $data[ 0 ] }; pp \@xformed; __DATA__ 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16

Output:

C:\test>1157088.pl [[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]] [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: How to warp an array by trading X/Y coordinates (rows/columns)
by Polyglot (Chaplain) on Mar 08, 2016 at 15:50 UTC

    Wow, you both are fast! Thank you! I thought there must be a way to do this with map. I'm not working on single characters, but with split I think I can find a suitable delimiter. (In my case, I'm actually working with LaTeX codes for each entry, so each array "element" is actually a piece of code text.) I'll give your suggestion a try.

    Blessings,

    ~Polyglot~

      I'm not working on single characters, but with split I think I can find a suitable delimiter.

      I was just being lazy. It works exactly the same for strings provided they do not contain spaces:

      C:\test>1157088.pl [ ["one", "five", "nine", "thirteen"], ["two", "six", "ten", "fourteen"], ["three", "seven", "eleven", "fifteen"], ["four", "eight", "twelve", "sixteen"], ] [ ["one", "two", "three", "four"], ["five", "six", "seven", "eight"], ["nine", "ten", "eleven", "twelve"], ["thirteen", "fourteen", "fifteen", "sixteen"], ]

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.