Here is an exercise:
Write a program that acts like cat, but reverses the order of the lines of
all the files specified on the command line. It should also reverse the
content of each file.
Ie
% perl.pl txt1 txt2
2txet si sihT
1txet si sihT
%
The way I did this was:
@ARGV = reverse(@ARGV);
while (<>) {
my $line = reverse($_);
print "$line\n";
Which works absolutely fine using perl -w and use strict; use warnings;
But, the book say:
@ARGV = reverse @ARGV;
print reverse <>;
I tested this, and I simply can't get it to work. I understand the concept
the book is using, and I would think it should work, but it doesn't.
My version is v5.6.0. The book is Learning Perl by O'Reilly.
Is the book wrong, or am I missing something?
PS: The solution from the book doesn't reverse the files on the command, or
the content of the files. So:
% booksultion.pl txt1 txt2
This is text1
This is text2
%
Could anyone help me with getting the book solution to work, as my code
seems a bit bloated.
--
T.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]