#!/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) { # Combined the first two conditionals to reduce indentation if (-d $maid_dir and $maid_dir=~m%\d+\s[A-Z]%){ # match the dir name my $seq_dir = $maid_dir."/sequencing/"; chdir ($maid_dir) or die "Can't chdir to $maid_dir: $!\n"; next if (-M $seq_dir > 1.0); chdir ($seq_dir) or die "Can't chdir to $seq_dir: $!\n"; #print Dumper ($maid_dir, $seq_dir); opendir my $dh, "$seq_dir" or die "Can't open $seq_dir: $!\n"; if(-d $seq_dir){ my @files = readdir $dh; #my $path = @_; 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){ # This is output, not input. Renamed variable accordingly. 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; } #open( my $out, ">>".$seq_dir."/".$fa); print $out, "\n" ;#"$hu,$hd,$lt\n"; print Dumper($f); close($out); close($hu_file); close($hd_file); close($lt_file); } } } } } }