On 3/11/2004 11:05 PM, Mame Mbodji wrote:

This is a hwk, but I never asked for a complete answer. I just needed guidance because I was lost. Thank you anyway.

Did you understand the hint I gave earlier? Your code


while(my @line = <REGFILE>) {
  foreach my $lin(@line){
    my @lines = $lin;
    print reverse(@lines);
  }
}

is equivelant to:

my @line = <REGFILE>;
foreach my $lin(@line){
  my @lines = $lin;
  print reverse(@lines);
}

because @line gets the whole file at one time, so the while loop only loops once. (put a print statement just after the while line to see for yourself.)

The variable @line should probably be named @lines (plural) because the array contains all lines in the file; each element in the array is a line in the file.

my @lines = <REGFILE>;

If you want the last line first and the first line last you'll need to reverse the elements in that array...

Next you'll need to iterate over each line and break up the string of characters into an array so you can reverse them. There are several ways to break a string into an array of characters (unpack,substr,split), but the common idiom in this case is to use split. The documentation for split will tell you exactly how to split the string into an array of characters.

Let us know if you need more hints.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to