#!/usr/bin/perl use strict; use File::Copy; use File::Glob ':glob'; use Data::Dumper; my %hu_hd_ltvecsmall=(); &cp_to_sequencing_dir; #&get_directory; foreach my $k (keys(%hu_hd_ltvecsmall)){ #get the array from the array reference. my @arr=@{$hu_hd_ltvecsmall{$k}}; #skip unless we have 3 files in the array next unless scalar @arr == 3; my $komp_dir = get_directory($k); print Dumper ($komp_dir); $komp_dir = $komp_dir."\\sequencing"; print Dumper ($komp_dir); #now iterate through the array, copying the files. The maid number is ($k) foreach my $f (@arr){ print Dumper($f, $komp_dir); copy("$f","$komp_dir"); } } #=cut sub cp_to_sequencing_dir{ my @dirs = glob("C:\\Documents and Settings\\mydirectory\\Desktop\\KOMP\\*"); foreach my $komp_dir(@dirs){ if (-d $komp_dir){ # directory check if ($komp_dir=~m%\d+\s[A-Z]%){ # match the dir name opendir (my $dh, $komp_dir); my @files=readdir $dh; for my $f(@files){ if ($f =~ m/(\d*)(HU|HD|Ltvec_small)/){ # capture the file name and the int string #print "$1 $f\n"; push @{$hu_hd_ltvecsmall{$1}}, $f; # create a array reference } } } } } } sub get_directory{ my @dirs = glob("C:\\Documents and Settings\\mydirectory\\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 return $maid_dir; } } } }