how can I do this mv ($file $new_file/$1) or die("Errors 2")
;
so it would stop the script in terminal if the file is not found?
otherwise it keeps repeating and repeating and I need to restart putty session so i would be able to type something
how can I do this mv ($file $new_file/$1) or die("Errors 2")
;
so it would stop the script in terminal if the file is not found?
otherwise it keeps repeating and repeating and I need to restart putty session so i would be able to type something
use autodie;
rename($file, "$dir/$newname")
What about this then:
if ( -f $file ) {
rename($file, "$dir/$newname")
or die("Could not rename '$file' to '$dir/$newname'");
} else {
die("File '$file' does not exist");
}
Please read the manual for the rename()
function to see its limitations (perldoc -f rename
) and what you might want to do about it (e.g., use move()
from the File::Copy
module).