Hi Perl Experts:
I am relatively new to perl and did try to solve the problem by searching books and web but could not exactly solve it. Here is the problem. I want to gather "*.igf" files and put all the lines from these files in a larger file. However, each small file has a header on the first line. I want header only once in a bigger file. My current code does everything fine except content from file other than first file is shifted and it shifts the format. My question is how to discard first header line except when it is the first file but still maintain the format. Below is the code.
Thank you for your help.
DeepNik
I am relatively new to perl and did try to solve the problem by searching books and web but could not exactly solve it. Here is the problem. I want to gather "*.igf" files and put all the lines from these files in a larger file. However, each small file has a header on the first line. I want header only once in a bigger file. My current code does everything fine except content from file other than first file is shifted and it shifts the format. My question is how to discard first header line except when it is the first file but still maintain the format. Below is the code.
Thank you for your help.
DeepNik
Code:
my @igf_files = glob("*.igf");
my $all_igf = "all_igf.igf";
my $counter = 0;
foreach my $fileigf (@igf_files) {
if ($counter==0){
open (IGF,"<$fileigf");
open (ALLIGF,"+>>$all_igf");
while(<IGF>)
{
print ALLIGF $_;
}
close (IGF );
close ( ALLIGF );
$counter++;
}
else{
open (IGF,"<$fileigf");
my @lines =(<IGF>);
open (ALLIGF,"+>>$all_igf");
{
print ALLIGF @lines[1..$#lines];
}
close (IGF);
close ( ALLIGF );
}
}
Comment