Anto_ch has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I am getting some troubles with arrays. I have two array with multiple columns and I'd like to merge them side by side. I tryed the join function but the output that gives is only the first array after the second one, instead to put the second next to first. Not that the arrays has not the same number of columns but have the same number of lines
here the sample array i use to test my code:
array 1
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
array2
a b c d
b c d e
f g h i
l m n o
p q r s
output I expect to have:
1 2 3 4 5 a b c d
2 3 4 5 6 b c d e
3 4 5 6 7 f g h i
4 5 6 7 8 l m n o
5 6 7 8 9 p q r s
output I have with join:
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
a b c d
b c d e
f g h i
l m n o
p q r s
any help would be appreciated, thanks in advance Ause strict; use warnings; open (POSITION, "path to file"); my(@array1) = <POSITION> ; close POSITION ; open(APRI2, "path to file") ; my(@array2) = <APRI2>; close APRI2; my @join = (@array1, @array2); print @join; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multicolumn files
by cheekuperl (Monk) on Jun 06, 2012 at 16:29 UTC | |
|
Re: multicolumn files
by stevieb (Canon) on Jun 06, 2012 at 17:01 UTC | |
by Anto_ch (Initiate) on Jun 06, 2012 at 17:17 UTC | |
by stevieb (Canon) on Jun 06, 2012 at 17:35 UTC | |
|
Re: multicolumn files
by kcott (Archbishop) on Jun 07, 2012 at 01:58 UTC | |
|
Re: multicolumn files
by 2teez (Vicar) on Jun 06, 2012 at 18:06 UTC |