Aimal Pashtoonmal wrote:
> Dear folks,
>
> I have 2 files each contain a column of data, I want to combine them
> into 1 file with the 2 columns next to each other, eg:
>
> file_1:
> 12
> 13
> 14
> 3
>
> file_2:
> 3
> 45
> 34
> 56
>
> desired output:
>
> 12 3
> 13 45
> 14 34
> 3 56
There was a problem identical to this just four days ago. This is
the solution that I proposed, which will handle as many files as
you want and treats each line as series of space-separated values.
use strict;
use warnings;
local @ARGV = qw( file1.txt file2.txt );
my @fds;
foreach (@ARGV) {
open (my $fd, $_) or die $!;
push (@fds, $fd);
}
my @line;
do {
undef @line;
FILE:
for (@fds){
for (scalar <$_>) {
next FILE unless defined;
push @line, split (' ', $_);
}
}
print "@line\n";
} while @line;
close foreach @ARGV;
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]