develooper Front page | perl.beginners | Postings from February 2002

Is O'Reilly wrong?

Thread Next
February 24, 2002 10:48
Is O'Reilly wrong?
Message ID:
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.

% 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:
% 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.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About