3 # Extra credit exercise: write a program to add a copyright line to
4 # all of your exercise answers so far, by placing a line like:
6 # ## Copyright (C) 2021 by Your Name <yourname@ircnow.org>
8 # ## Permission is granted to use, copy, modify, and/or distribute
9 # ## this work for any purpose with or without fee. This work is
10 # ## offered as-is, with absolutely no warranty whatsoever. The
11 # ## author is not responsible for any damages that result from
14 # in the file immediately after the "shebang" line. You should edit
15 # the files "in place,", keeping a backup. Presume that the program
16 # will be invokved with the filenames to edit already on the
19 # Extra extra credit exercise: modify the previous program so that
20 # it doesn't edit the files that already contain the copyright
21 # line. As a hint on that, you might need to know that the name of
22 # the file being read by the diamond operator is in $ARGV.
29 my $copyright = <<'END_COPYRIGHT';
30 ## Copyright (C) 2023 by jrmu <jrmu@ircnow.org>
32 ## Permission is granted to use, copy, modify, and/or distribute
33 ## this work for any purpose with or without fee. This work is
34 ## offered as-is, with absolutely no warranty whatsoever. The
35 ## author is not responsible for any damages that result from
39 foreach my $file (@ARGV) {
42 foreach my $file (@ARGV) {
43 open my $fh, '<', $file or die "Unable to open $file: $!";
44 my $lines = join '', <$fh>;
45 if ($lines =~ m/\A#!.*(\n|\r)*\Q$copyright\E/mi) {
51 @ARGV = sort keys %files;
55 s@\A(#!.*\n)@$1$copyright@m;