Blob


1 #!/usr/bin/perl
3 # If your operating system supports it, write a program that works
4 # like ln, making a hard link from the first command-line argument
5 # to the second. (You don't need to handle options of ln or more
6 # arguments.) If your system doesn't have hard links, just print
7 # out a message telling which operation you would perform if it
8 # were available. Hint: this program has something in common with
9 # the previous one--recognizing that could save you time in coding.
11 use v5.24;
12 use warnings;
13 use strict;
14 use utf8;
15 use File::Spec::Functions;
16 use File::Basename;
18 if (scalar(@ARGV) != 2) {
19 die "Usage: $0 source target";
20 }
21 my ($source, $target) = @ARGV;
22 if (-d $target) {
23 $target = catfile($target, basename($source));
24 }
26 link $source $target or die "Unable to link "$source" to "$target": $!";