Blob
1 #!/usr/bin/perl3 # Modify the previous program to change every Fred to Wilma and4 # every Wilma to Fred. Now input like fred&wilma should look like5 # Wilma&Fred in the output.7 use warnings;8 use strict;9 use utf8;11 if (scalar(@ARGV) != 1) {12 die "Usage: $0 filename";13 }14 my $filepath = ($ARGV[0] =~ s/.[^.]*\z/.out/r);15 open my $fh, ">", $filepath or die "Unable to write to '$filepath': $!";17 while (<>) {18 chomp;19 s/Fred/\n/ig;20 s/Wilma/Fred/mig;21 s/\n/Wilma/mig;22 print $fh "$_\n";23 }