Blob


1 #!/usr/bin/perl
3 # If your operating system supports it, fix up the program from the previous
4 # exercise to allow an optional -s switch before the other arguments to
5 # indicate that you want to make a soft link instead of a hard link. (Even if
6 # you don't have hard links, see whether you can at least make soft links with
7 # this program.)
9 use v5.24;
10 use warnings;
11 use strict;
12 use utf8;
13 use File::Spec::Functions;
14 use File::Basename;
16 my $symlink = $ARGV[0] eq '-s';
17 shift @ARGV if ($symlink);
18 if (scalar(@ARGV) != 2) {
19 die "Usage: $0 [-s] source target";
20 }
21 my ($source, $target) = @ARGV;
22 if (-d $target) {
23 $target = catfile($target, basename($source));
24 }
26 if ($symlink eq '-s') {
27 symlink $source $target or die "Unable to symlink "$source" to "$target": $!";
28 } else {
29 link $source $target or die "Unable to link "$source" to "$target": $!";
30 }