I’ve written some code that will copy and move files from one folder to another. This code works fine on it’s own but when I try to add a while loop to the code I keep getting errors. The while loop is working fine on it’s own as well when I test it. I just can’t seem to figure out what is wrong with the code. I’m new to using Perl and was wondering if someone could point out where I’m going wrong. Any help would be great. Thanks. : )
use File::Copy;
use File::Find;
my @source = qw (source);
my $target = q{target};
while
{sleep (5);
find(
sub {
if (-f) {
print "$File::Find::name -> $target";
copy($File::Find::name, $target)
or die(q{copy failed:} . $!);
}
},
@source
);
}
EDIT: Sorry I don’t think I was clear. I’m wanting this code to loop every X amount of seconds. I was setting it up as 5 seconds to test it out.
You’re missing the expression that indicates when to exit the loop.
If you want an endless loop, you can use