1 ffd9a51f 2023-08-04 jrmu #!/usr/bin/perl
3 ffd9a51f 2023-08-04 jrmu #Write a program that acts like cat, but reverses the order of the output
4 ffd9a51f 2023-08-04 jrmu #lines. (Some systems have a utility like this named tac.) If you run yours as
5 ffd9a51f 2023-08-04 jrmu #./tac fred barney betty, the output should be all of file betty from last line
6 ffd9a51f 2023-08-04 jrmu #to first, then barney, and then fred, also from last line to first. (Be sure
7 ffd9a51f 2023-08-04 jrmu #to use the ./ in your program's invocation if you call it tac so that you
8 ffd9a51f 2023-08-04 jrmu #don't get the system's utility instead!)
12 ffd9a51f 2023-08-04 jrmu use warnings;
17 ffd9a51f 2023-08-04 jrmu #foreach (@ARGV) {
18 ffd9a51f 2023-08-04 jrmu # open my $fh, '<', $_;
19 ffd9a51f 2023-08-04 jrmu # push @lines, <$fh>;
20 ffd9a51f 2023-08-04 jrmu # close $fh;
22 ffd9a51f 2023-08-04 jrmu #print reverse @lines;
23 ffd9a51f 2023-08-04 jrmu print reverse <>;