lomSpace has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I am trying to resolve a looping issue which causes my script
to append the files 4x instead of once.
to append the files 4x instead of once.
Any ideas?#!/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); } } } } } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: loop issue...
by bellaire (Hermit) on Mar 20, 2009 at 14:40 UTC | |
| |
Re: loop issue...
by kennethk (Abbot) on Mar 20, 2009 at 14:44 UTC | |
by Fletch (Bishop) on Mar 20, 2009 at 15:22 UTC | |
by Nkuvu (Priest) on Mar 20, 2009 at 16:52 UTC | |
by lomSpace (Scribe) on Mar 20, 2009 at 16:35 UTC | |
by Bloodnok (Vicar) on Mar 20, 2009 at 14:54 UTC | |
by lomSpace (Scribe) on Mar 20, 2009 at 16:34 UTC |
Back to
Seekers of Perl Wisdom