On 3/11/2004 10:01 PM, [EMAIL PROTECTED] wrote:

Sorry, no answers. This sounds like a school assignemnt. But I'll offer a few hints ;-)

I have a text file with 5 or more lines as in:

My name is this and that
I live in Denver Colorado
I live in washington
I live in Denver Virginia


I am trying to read this file and print each line and each word in reverse order as in:


ainigriv revned ni evil I (the output starts with the last last of the file and 
reverse each work as well).
Here is what I have done, but does not work:

always: use strict; use warnings;

print "Enter a file name:\n";
my $file = <STDIN>;
open (REGFILE, "$file") or die ("Cannot open file: $file: $!");

The diamond operator <> can be used in two different contexts: 1) in scalar context (my $line = <>) it reads one line at a time from the file, 2) in array context (my @lines = <>) it reads the entire file at once. Below you are reading the entire file into @line at one time. I.e. you could remove the 'while' statement and nothing would change.


while(my @line = <REGFILE>) {

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

}

Any ideas! Thanks in advance

See if the above gets you any further along and let us know.


Regards,
Randy.



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