1 ffd9a51f 2023-08-04 jrmu #!/usr/bin/perl
2 ffd9a51f 2023-08-04 jrmu ## Copyright (C) 2023 by jrmu <jrmu@ircnow.org>
4 ffd9a51f 2023-08-04 jrmu ## Permission is granted to use, copy, modify, and/or distribute
5 ffd9a51f 2023-08-04 jrmu ## this work for any purpose with or without fee. This work is
6 ffd9a51f 2023-08-04 jrmu ## offered as-is, with absolutely no warranty whatsoever. The
7 ffd9a51f 2023-08-04 jrmu ## author is not responsible for any damages that result from
8 ffd9a51f 2023-08-04 jrmu ## using this work.
10 ffd9a51f 2023-08-04 jrmu # Extra credit exercise: write a program to add a copyright line to
11 ffd9a51f 2023-08-04 jrmu # all of your exercise answers so far, by placing a line like:
13 ffd9a51f 2023-08-04 jrmu # ## Copyright (C) 2021 by Your Name <yourname@ircnow.org>
15 ffd9a51f 2023-08-04 jrmu # ## Permission is granted to use, copy, modify, and/or distribute
16 ffd9a51f 2023-08-04 jrmu # ## this work for any purpose with or without fee. This work is
17 ffd9a51f 2023-08-04 jrmu # ## offered as-is, with absolutely no warranty whatsoever. The
18 ffd9a51f 2023-08-04 jrmu # ## author is not responsible for any damages that result from
19 ffd9a51f 2023-08-04 jrmu # ## using this work.
21 ffd9a51f 2023-08-04 jrmu # in the file immediately after the "shebang" line. You should edit
22 ffd9a51f 2023-08-04 jrmu # the files "in place,", keeping a backup. Presume that the program
23 ffd9a51f 2023-08-04 jrmu # will be invokved with the filenames to edit already on the
24 ffd9a51f 2023-08-04 jrmu # command line.
26 ffd9a51f 2023-08-04 jrmu # Extra extra credit exercise: modify the previous program so that
27 ffd9a51f 2023-08-04 jrmu # it doesn't edit the files that already contain the copyright
28 ffd9a51f 2023-08-04 jrmu # line. As a hint on that, you might need to know that the name of
29 ffd9a51f 2023-08-04 jrmu # the file being read by the diamond operator is in $ARGV.
31 ffd9a51f 2023-08-04 jrmu use warnings;
35 ffd9a51f 2023-08-04 jrmu $^I = ".bak";
37 ffd9a51f 2023-08-04 jrmu while (<>) {
39 ffd9a51f 2023-08-04 jrmu my $copyright = <<'END_COPYRIGHT';
40 ffd9a51f 2023-08-04 jrmu ## Copyright (C) 2023 by jrmu <jrmu@ircnow.org>
42 ffd9a51f 2023-08-04 jrmu ## Permission is granted to use, copy, modify, and/or distribute
43 ffd9a51f 2023-08-04 jrmu ## this work for any purpose with or without fee. This work is
44 ffd9a51f 2023-08-04 jrmu ## offered as-is, with absolutely no warranty whatsoever. The
45 ffd9a51f 2023-08-04 jrmu ## author is not responsible for any damages that result from
46 ffd9a51f 2023-08-04 jrmu ## using this work.
47 ffd9a51f 2023-08-04 jrmu END_COPYRIGHT
49 ffd9a51f 2023-08-04 jrmu s@\A(#!.*\n)@$1$copyright@m;