in reply to file copy undefined?

Perl is case sensitive, so Copy and copy are different. Your issue is on line 13.

Update: Missed the second part of the question. When you use strict;, you must explicitly declare each variable with my. You also appear not to be using copy correctly. Working code:

use File::Copy; use strict; use warnings; my $dirpath="C:\\inetpub\\performancetesting\\output\\new\\mlx\\aar"; my $dirpath2="c:\\temp"; opendir(IN,"$dirpath") or die "opening directory failed:$!"; while (defined (my $file = readdir(IN)) ) { my @files = split / /,$file; foreach my $filename (@files) { copy ("$dirpath".$filename, "$dirpath2".$filename) or warn "Ca +n't open the file yet $filename\n:$!"; open INPUT, "<", $dirpath.$filename or die "Open failure: $!"; until (eof(INPUT)) { chomp(my $line = <INPUT>); # print contents of the file or do anything print "$line"; } close INPUT; } } closedir(IN);

Replies are listed 'Best First'.
Re^2: file copy undefined?
by grashoper (Monk) on Apr 14, 2009 at 16:27 UTC
    I still get the following 2 errors not sure why. can't open the file yet . :no such file or directory at copy.pl line 13 open failure permission denied at copy.pl line 14.
      The answer is in your errors: The script does not see the file in question on your system. I would suggest adding print statements on your file paths and then checking if they correspond to the files you think you are opening.
      Do you have a separator between your directories and your filename? You didn't in your original post. ie shouldn't $dirpath end with a pair of backslashes?


      Unless I state otherwise, all my code runs with strict and warnings
        yeah it should have had slashes thanks, now it does copy all the files in the dir, however I still get a cannot open the file yet but now its only happening twice, what is causing this error message is it trying to copy . and ..? apparenty that is what its doing, how do I get rid of it..I tried this but it didn't work I know its only happening because of the warning, but I want to get rid of it as it isn't really an error. not sure how to incorporate grep here..
        use File::Copy; #use strict; my $dirpath="C:\\inetpub\\performancetesting\\output\\new\\mlx\\aar\\" +; my $dirpath2="c:\\temp\\"; opendir(IN,"$dirpath") or die "opening directory failed:$!"; while (defined (my $file = readdir(IN)) ) { push (my @files, $file); foreach my $filename (@files) { copy ("$dirpath".$filename, "$dirpath2".$filename) or warn "Can't open + the file yet $filename\n:$!"; need something like my @files=grep { $_ ne '.' && $_ ne '..'} } } closedir(IN);