Hello,
I have not been successful in passing the return value from
my subroutine 'get_directory' to the file::copy function.
I am using Data::Dumper which has enabled me to see
the variables that I am passing to the file::copy function.
I have the files, but the directory that I want to copy them to is wrong.
When I test my sub get_directory:
It returns a list of the directories that I want to searchsub 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 #my $sub_dir = "C:\\Documents and Settings\\mydirector +y\\Desktop\\KOMP\\$maid_dir"; print "$maid_dir\n"; } } } }
The second variable being passed to the file::copy function is not#!/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 i +s ($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; } } } }
$VAR1 = '13129HD.fa' should be copied to $VAR2 = 'C:\Documents and Settings\mydirectory\Desktop\KOMP\13129 Raet1d (46)\sequencing'It is not iterating through the dir to find the match and
In reply to Having trouble returning the correct values from my sub by lomSpace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |