perlquestion
lomSpace
Hello,
I am trying to resolve a looping issue which causes my script<br> to append the files 4x instead of once. <br>
<c>
#!/usr/bin/perl
use strict;
use Data::Dumper;
use File::Glob ':glob';
my @dirs = glob("C:/Documents and Settings/mydir/Desktop/KOMP/*");
foreach my $maid_dir(@dirs){
if (-d $maid_dir){ # directory check
if ($maid_dir=~m%\d+\s[A-Z]%){ # match the dir name
my $seq_dir = $maid_dir."/sequencing/";
chdir ($maid_dir);
#next if (-M $seq_dir > 1.0);
chdir ($seq_dir);
#print Dumper ($maid_dir, $seq_dir);
opendir my $dh, "$seq_dir";
if(-d $seq_dir){
my @files = readdir $dh;
for my $f(@files){
if($f=~ m%^(\d*)(HU.fa|HD.fa|Ltvec_small.FA|_fasta)$%){
my ($fa, $hu, $hd, $lt)= ($1."_fasta", $1."HU.fa", $1."HD.fa", $1."Ltvec_small.FA");
if(-e $fa){
open (my $out, ">>".$seq_dir."/".$fa) or die "Can't open $seq_dir/$fa for append: $!\n";
# Append the contents of the three files to $fa
open my $hu_file, '<', $hu or die "Can't open $hu: $!\n";
while (my $line = <$hu_file>) {
print $out $line;
}
open my $hd_file, '<', $hd or die "Can't open $hd: $!\n";
while (my $line = <$hd_file>) {
print $out $line;
}
open my $lt_file, '<', $lt or die "Can't open $lt: $!\n";
while (my $line = <$lt_file>) {
print $out $line;
}
print $out, "\n";
#print Dumper($f);
close($out);
close($hu_file);
close($hd_file);
close($lt_file);
}
}
}
}
}
}
}
</c>
Any ideas?