Blob


1 #!/usr/bin/perl
3 # Write a program that works like mv, renaming the first
4 # command-line argument to the second command-line argument. (You
5 # don't need to handle any of the options of mv or additional
6 # arguments.) Remember to allow for the destination to be a
7 # directory; if it is, use the same original basename in the new
8 # directory.
10 use v5.24;
11 use warnings;
12 use strict;
13 use utf8;
14 use File::Spec::Functions;
15 use File::Basename;
17 if (scalar(@ARGV) != 2) {
18 die "Usage: $0 source target";
19 }
20 my ($source, $target) = @ARGV;
21 if (-d $target) {
22 $target = catfile($target, basename($source));
23 }
25 rename $source $target or die "Unable to move "$source" to "$target": $!";