Blob


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