in reply to Copying files between directories. How can I improve this code.
Well, for one thing there's your formatting, or rather the total lack thereof; see perlstyle and/or install perltidy.
Another nit is you don't check the return from opendir; ALWAYS CHECK THE RETURN VALUE FROM SYSTEM CALLS.
Then there's the strange line with @Filenames all by itself in void context; we'll be generous and presume that's cruft from trying to print its context that got left in.
I would have written your print line in the last loop as print "\$destFile = $destFile\n"; one backwhack's less noise than the separate concatenation (that's again a minor nit).
As for an actual logical error, it doesn't appear that $destFile will contain a useable path as $newpath doesn't end in a "/". Consider using File::Spec for a portable way of building paths.
Update: Aaah, that @Filenames on its own was probably your trying to declare it; as is pointed out below you need to do that outside the loop.
|
|---|