http://www.perlmonks.org?node_id=1041667

stamp1982 has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I need help with my perl code to read from a .txt file and print out in reverse order. Write a Perl program to read a file, and then print its lines in reverse order, the last line first. This is what I have so far but I am stuck and it would not work. What am I missing out

# Open a .txt file open(seq1, "<seq1.txt") or die $!; #Assign open files to arrays my @seq1 = <seq1>; print "@seq1"; print reverse @seq1;

Replies are listed 'Best First'.
Re: Read reverse from a file
by davido (Cardinal) on Jun 30, 2013 at 23:25 UTC

    We don't know in what way it's not working. ...well, I can see one way. But I need to hear from you what messages you're getting (if any), or what "would not work" means. Example input and the output it produces, along with the output you desire, are all important information so that we don't have to guess at your needs, or at what's wrong.

    Please follow up in this thread with example input, expected output, and exactly what you're seeing instead. Then we can explain why you are seeing what you are seeing, and what needs to change so that you can see what you want.


    Dave

Re: Read reverse from a file
by smls (Friar) on Jun 30, 2013 at 23:30 UTC

    The line

    print "@seq1";

    was probably intended to do something different than what it actually does.
    Other than that, the program should work. If you remove that line, then afaict the program's function will be exactly as you specified: "read a file, and then print its lines in reverse order".

      Thanks! it did work!