Hello,
I am trying to resolve a looping issue which causes my script
to append the files 4x instead of once.
#!/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 d
+ie "Can't open $seq_dir/$fa for append: $!\n";
# Append the contents of the three files t
+o $fa
open my $hu_file, '<', $hu or die "Can't o
+pen $hu: $!\n";
while (my $line = <$hu_file>) {
print $out $line;
}
open my $hd_file, '<', $hd or die "Can't o
+pen $hd: $!\n";
while (my $line = <$hd_file>) {
print $out $line;
}
open my $lt_file, '<', $lt or die "Can't o
+pen $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);
}
}
}
}
}
}
}
Any ideas?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.