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