The rename()
method renames a file in Perl.
rename(currentName, newName)
currentName
: This is the current file’s name.newName
: This is the new name we want to give the file.The value returned is either 1
or 0
. 1
is returned if the process was successful, and 0
is returned if it was unsuccessful.
# rename files and print resultsprint rename("main.perl", "app.perl");print "\n";print rename("test.txt", "newtest.txt");
main.perl
.main.perl
using the rename()
function and print the result. This is successful. Hence, 1
is returned.0
because it was not successful.