OK, that's the code. But what do you expect from us now?

Did you check, what toolic and me already suggested?

Do you still have problems? What kind of problems? What happens when you execute the script? What do you want to happen?

At least, my %files(); causes an syntax error.

You still don't check whether mkdir is successful or not.

I just rewrote your script to get it syntactically OK. I think there is more optimization possible.
I don't know, if it does what you want, but you might get the idea, what I meant with my previous comments.

#! /usr/bin/perl use strict; use warnings; use DateTime; use File::Copy; use File::Find; use File::stat; use Time::localtime; use File::Spec::Functions qw( catdir catfile ); my $now = DateTime->now( time_zone => 'floating' ); my $yesterday = $now->substract( days => 1 ); my $year = $yesterday->year; my $month = $yesterday->month; my $month_abbr = uc( $yesterday->month_abbr ); my $day = $yesterday->day; my $year_abbr = substr $year, 2, 2; my $mdy = $now->strftime( "%m-%d-%y" ); print "$year\t$year_abbr\t$month\t$month_abbr\t$day\n"; my $basedir = '/Users/mgavi.brathwaite/Desktop/BioinfDev/SequenceAssem +blyProject'; my $root = catdir( $basedir, "Sequencing_Results/Results $year/New + Version/Amanda Li/$month_abbr" ); my $komp_dir = catdir( $basedir, 'KOMP' ); #> sub routines #> ------------------------------------------------------------ sub wanted { # return if current filename ends with 'xls' return if $File::Find::name =~ m/xls\z/; # return if file is younger than 1 day return if -M $File::Find::name > 1.0; # determine maid number if ( my ( $maid ) = $File::Find::name =~ m{/(\d*)} ) { # store full path to file if maid number could be determined; +see: "perldoc perldsc", Hashes of Arrays push @{ $files{$maid} }, $File::Find::name; } } sub maid_dirs { my ( $maid ) = @_; my @dirs = glob( catfile( $komp_dir, '*' ) ); for my $dir ( @dirs ) { return $dir if -d $dir and $dir =~ m{/$maid\D}; } # if no suitable dir was found return undef; } #> main script #> ------------------------------------------------------------ # determine files my %files; find( \&wanted, $root ); for my $maid ( keys %files ) { my @files = @{ $files{$maid} }; next if @files != 4; if ( my $dest_dir = maid_dirs( $maid ) ) { my $directory = catdir( $dest_dir, 'sequencing' ); mkdir( $directory, 0755 ) or die "mkdir failed: $!\n"; for my $file ( @files ) { copy( $file, catfile( $directory, $file ) ) or die "copy f +ailed: $!\n"; } } } print "Job done\n";

In reply to Re^3: Trouble copying files from an array to new dir by linuxer
in thread Trouble copying files from an array to new dir 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.