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:

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 #my $sub_dir = "C:\\Documents and Settings\\mydirector +y\\Desktop\\KOMP\\$maid_dir"; print "$maid_dir\n"; } } } }
It returns a list of the directories that I want to search
for matches with the files that I want to copy to the matching directories.
When I run the &get_directory in my program:
#!/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; } } } }
The second variable being passed to the file::copy function is not
the directory that the files should be copied to.
Example:
$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
then copy. Any suggestions?


In reply to Having trouble returning the correct values from my sub by lomSpace

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.