i have multiple text files.I have written code to input 2 files through shell and merge them.But how do i merge multiple files.Is system command useful in this purpose.
my @a = read_file($file1)
or die "couldn't read $file1 - $!";
my @b = read_file($file2)
or die "couldn't read $file2 - $!";
my $combined = {}; # hashref
my $i=0;
foreach (@a) {
chomp;
$combined->{$i}{b} = '' unless defined $combined->{$i}{b};
$combined->{$i++}{a} = $_;
}
$i=0;
foreach (@b) {
chomp;
$combined->{$i}{a} = '' unless defined $combined->{$i}{a};
$combined->{$i++}{b} = $_;
}
foreach my $i (sort {$a<=>$b} keys %$combined) {
print $combined->{$i}{a}, ("\t" x 2), $combined->{$i}{b}, "\n";
}