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 # Modify the previous program to change every Fred to Wilma and
11 # every Wilma to Fred. Now input like fred&wilma should look like
12 # Wilma&Fred in the output.
14 use warnings;
15 use strict;
16 use utf8;
18 if (scalar(@ARGV) != 1) {
19 die "Usage: $0 filename";
20 }
21 my $filepath = ($ARGV[0] =~ s/.[^.]*\z/.out/r);
22 open my $fh, ">", $filepath or die "Unable to write to '$filepath': $!";
24 while (<>) {
25 chomp;
26 s/Fred/\n/ig;
27 s/Wilma/Fred/mig;
28 s/\n/Wilma/mig;
29 print $fh "$_\n";
30 }