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

Very Basic <> Question

Thread Next
Michael Norris
March 18, 2002 14:10
Very Basic <> Question
Message ID:
Forgive me for such a basic question, I'm brand spanking new to Perl and programming in general.  

This is from the exercises in "Learning Pearl", chapter 6, exercise 1.

The goal is to reverse the order of all the lines of a specified file.

The very simple answer given in the book is as follows:
print reverse <>;

Fair enough, but I wanted to explore and try a different way, I came up with the following which doesn't work...

while (<>) {
@reverselist = reverse <>;
print "@reverselist";

This reverses everything, BUT the last line of the given file.  Can someone tell me why this pauses on the last line?


Surf on! Get a free and secure email account and more @

Run a small business? Then you need professional email like from

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