perl - Unpacking ArrayRef into X separate arguments -
Looking at a seraph that contains other surrefraces, is it possible to combine nested serfact together using zip function?
For example, it has been given:
My $ matrix = [[qw (1 2 3 4)], [qw (5 6 7 8)] , [Qw (9 10 11 12)], [Q (13 14 15 16)], [QW (17 18-20)],];
I would like to zip each line together so that I can move. Expected output:
[[qw (1913)], [qw (2 6 10 14 18)], [qw (3 7 11 15 9)], [qw ( 4 8 12 16 20)],];
My initial efforts were as follows:
# I expected that the function will open @zip matrix @ logic; #Error: There is not enough logic for the list: MoreUtils :: Mesh Spiral. On page 17 # I thought this piece would be enough to open them @ $ matrix [1..scalar @ $ matrix-1]; # Error: 1 Arg Type for list: MoreUtils :: Aries should be array array (not piece of array)
I'm sure this is a way of doing it properly, I Just seeing it, any help will be appreciated.
zip
function is very annoying because it uses or something like crazy . You must do an ampersand-call to override the prototype: & amp; Zip (@ $ matrix)
.
However, you do not have to move the matrix, zip
(which is
[1, 5, 9, 13, 17, 2, 6, 10), 14, 18, 3, 7, 11, 15, 19, 4, 8, 12, 16, 20]
We can use a natatime
iterator combination with zip
:
$ myer = natatime @ $ matrix , & Amp; Zip (@ $ matrix); My @ transposed; While (My @column = $ ITAR-> ()) {Push @transpushed, \ @column;}
which works, but it is seriously eliminating the problem . Let's just swap index:
$ $ ($. $ # $ Matrix) $ $ ($. $ # $ Matrix-> [0]}) {$ transposed- & gt; [$ J] [$ i] = $ matrix- & gt; [$ I] [$ j];}}
Comments
Post a Comment