perl function rename

h‮t‬tps://www.theitroad.com

In Perl, the rename function is used to rename a file or directory. It takes two arguments: the old file name or path, and the new file name or path.

Here's an example that demonstrates how to use rename function in Perl:

# Rename a file
rename("old_file.txt", "new_file.txt") or die "Error renaming file: $!";

# Rename a directory
rename("old_dir", "new_dir") or die "Error renaming directory: $!";

In the above example, if the file or directory specified in the first argument doesn't exist, or if the second argument is the name of an existing file or directory, the rename function will fail and return false. In this case, the die function will be called and the script will exit with an error message.