> Forgive me for such a basic question,
> I'm brand spanking new to Perl and
> programming in general.  

The banner on the door says:

"beginners@perl"

so I guess we should say 'Welcome Friend' :)

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

s/Pearl/Perl/; # This is a regex BTW, just
               # in case you haven't seen them yet

> 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 <>;

Ah, but not the shortest.  Thanks to Eugene van
der Pijll, a Golfing great, we have:

#!/usr/bin/perl -p
$\=$_.$\}{

> 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?

while ($_ = read a line) {
    @reverse = reverse (read rest of lines);
    print @reverse; # Hasn't looked at $_
}

hence you miss the first line, which should really
be the end line now.

Jonathan Paton





__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to