[EMAIL PROTECTED] wrote:
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:

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

while(my @line = <REGFILE>) {

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

}

Any ideas! Thanks in advance

I am sure there is a better way...

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

while(my @line = <REGFILE>) {
    foreach $lin(@line){
        @lines =  split(" ", $lin);
        $revwords = join(" ", reverse @lines);
        print "$revwords","\n";
    }
}

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