Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Im new to programming and have a hard time understanding Perl. I have a problem with trying to copy over a file that has spaces in the file name('R_BCE_4WklyMonthlyTrackingReport District 110.pdf'). how would I concat the file name or what would be the best way to do this so that copy will be able to copy the file to my directory? Below is the code thanks in advance.
@dist_list = ("110 100 196"); @districts = ("110"); foreach my $dst (@districts) { foreach my $dist (@dist_list) { # Copies District files into the directories #print "$all_store_info\n"; my @array = split(/ / , $dist); #print "@array\n"; #print "{ $dst \n and $array[0] }\n"; if ($array[0] =~ /^$dst$/) { my $dt = $array[0]; my $rgn = $array[1]; my $grp = $array[2]; print "$dt test $rgn test $grp\n"; my $dir = "H:/Scripts/BestCreditEver/pdf_docs/company/R$rg +n/G$grp/D$dt"; if (-d $dir) { #print "It Exists: $dir\n"; copy 'R_BCE_4WklyMonthlyTrackingReport District 110.pd +f',"$dir/R_BCE_${acct_wk}WklyMonthlyTrackingReport District $array[0] +.pdf"; #print "H:/Scripts/BestCreditEver/pdf_docs/company/R$r +gn/G$grp/D$dt/R_BCE_${acct_wk}WklyMonthlyTrackingReport District ${dt +}.pdf\n"; } else { print "Does Not Exist: $dir\n"; #mkdir "H:/Scripts/BestCreditEver/pdf_docs/company/R$r +gn/G$grp/D$dt" unless -d "H:/Scripts/BestCreditEver/pdf_docs/company/ +R$rgn/G$grp/D$dt"; print "Dir $dir has been created.\n"; copy "R_BCE_${acct_wk}WklyMonthlyTrackingReport Distri +ct $array[0].pdf","$dir/R_BCE_${acct_wk}WklyMonthlyTrackingReport Dis +trict $array[0].pdf"; } } } }

Replies are listed 'Best First'.
Re: File NCopy concat
by chrism01 (Friar) on Sep 15, 2006 at 02:19 UTC
    One trick is to save the generated filenames into eg $src, $dest strings before you use them in the copy, then prefix & suffix the strings with single quotes, then submit the copy cmds.
    The single quotes should prevent the spaces being 'seen' by copy cmd's internal code.
Re: File NCopy concat
by GrandFather (Saint) on Sep 14, 2006 at 22:40 UTC

    What is copy?


    DWIM is Perl's answer to Gödel
      He might be using File::Copy...
        Yes, its actually File::NCopy.... the files needs to have space in them. So Im trying a find a way to do this keeping the spaces in.