in reply to multicolumn files

my @array1 = ( "1 2 3 4 5", "2 3 4 5 6", "3 4 5 6 7" ); my @array2 = ( "a b c d", "b c d e", "f g h i" ); my @join; for my $elem ( @array1 ){ push @join, "$elem " . shift @array2; } print "$_\n" for @join;

Output:

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

Also, you should use the three-argument form of open(), and inform if something goes wrong:

open my $fh, '<', 'path to file' or die "Can't open the damned file!: +$!";

Replies are listed 'Best First'.
Re^2: multicolumn files
by Anto_ch (Initiate) on Jun 06, 2012 at 17:17 UTC

    the array I used come from tab delimited text files, I tryied your code but I still get the same output as when I used join. thanks

      Ok, I tried it with files. Try changing the for loop I posted to this:

      for my $elem ( @array1 ){ my $arr2_elem = shift @array2; chomp( $elem, $arr2_elem ); push @join, "$elem $arr2_elem"; }