juanito23 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am struggling with an issue with printing 2 arrays. Let's say I have these 2 arrays:
@array1 = [1, 2, 3, 1, 2, 3, 1, 2, 3 ] @array2 = [blue, white, yellow, blue, white, yellow, blue, white, yell +ow]
IS there a way so I can have an output like
1 2 3 blue white yellow 1 2 3 blue white yellow 1 2 3 blue white yellow
so the idea would be printing 3 elements of each row and print them together. I can print wach array separated like this:
while (@array1){ push (@array_wb, $_[0]); push (@array_wb, $_[1] ); push (@array_wb, $_[2] . "\n"); push (@array_wb, $_[3]); push (@array_wb, $_[4] ); push (@array_wb, $_[5] . "\n"); push (@array_wb, $_[6]); push (@array_wb, $_[7] ); push (@array_wb, $_[8] . "\n"); print (@array_wb); }
So I can print both array separared, bue if I print both I get this:
I know this code is not ideal, but my goal here is to make a output print as I mentioned. Any ideas? Thanks!1 2 3 1 2 3 1 2 3 blue white yellow blue white yellow blue white yellow
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: issue with print/join 2 arrays
by toolic (Bishop) on Apr 29, 2014 at 16:36 UTC | |
|
Re: issue with print/join 2 arrays
by BrowserUk (Patriarch) on Apr 29, 2014 at 16:33 UTC | |
|
Re: issue with print/join 2 arrays
by roux.tophe (Novice) on Apr 29, 2014 at 16:48 UTC | |
|
Re: issue with print/join 2 arrays
by Not_a_Number (Prior) on Apr 29, 2014 at 18:08 UTC | |
by Laurent_R (Canon) on Apr 29, 2014 at 21:18 UTC | |
by Bloodnok (Vicar) on Apr 30, 2014 at 09:27 UTC | |
by juanito23 (Novice) on Apr 30, 2014 at 09:19 UTC | |
by choroba (Cardinal) on Apr 30, 2014 at 09:21 UTC | |
by Anonymous Monk on Apr 30, 2014 at 09:20 UTC | |
|
Re: issue with print/join 2 arrays
by RichardK (Parson) on Apr 29, 2014 at 17:08 UTC | |
by juanito23 (Novice) on Apr 29, 2014 at 18:37 UTC | |
by Not_a_Number (Prior) on Apr 29, 2014 at 19:02 UTC |