Blame


1 ffd9a51f 2023-08-04 jrmu #!/usr/bin/perl
2 ffd9a51f 2023-08-04 jrmu ## Copyright (C) 2023 by jrmu <jrmu@ircnow.org>
3 ffd9a51f 2023-08-04 jrmu ##
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.
9 ffd9a51f 2023-08-04 jrmu
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:
12 ffd9a51f 2023-08-04 jrmu #
13 ffd9a51f 2023-08-04 jrmu # ## Copyright (C) 2021 by Your Name <yourname@ircnow.org>
14 ffd9a51f 2023-08-04 jrmu # ##
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.
20 ffd9a51f 2023-08-04 jrmu #
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.
25 ffd9a51f 2023-08-04 jrmu #
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.
30 ffd9a51f 2023-08-04 jrmu
31 ffd9a51f 2023-08-04 jrmu use warnings;
32 ffd9a51f 2023-08-04 jrmu use strict;
33 ffd9a51f 2023-08-04 jrmu use utf8;
34 ffd9a51f 2023-08-04 jrmu
35 ffd9a51f 2023-08-04 jrmu $^I = ".bak";
36 ffd9a51f 2023-08-04 jrmu
37 ffd9a51f 2023-08-04 jrmu while (<>) {
38 ffd9a51f 2023-08-04 jrmu
39 ffd9a51f 2023-08-04 jrmu my $copyright = <<'END_COPYRIGHT';
40 ffd9a51f 2023-08-04 jrmu ## Copyright (C) 2023 by jrmu <jrmu@ircnow.org>
41 ffd9a51f 2023-08-04 jrmu ##
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
48 ffd9a51f 2023-08-04 jrmu
49 ffd9a51f 2023-08-04 jrmu s@\A(#!.*\n)@$1$copyright@m;
50 ffd9a51f 2023-08-04 jrmu
51 ffd9a51f 2023-08-04 jrmu print;
52 ffd9a51f 2023-08-04 jrmu }