in reply to Sed to perl conversion-- flipping lines in a file

my @lines = <DATA>; print reverse @lines; __DATA__ 1. text'1' 2. text'2' 3. text'3'

-Mark

Replies are listed 'Best First'.
Re: Re: Sed to perl conversion-- flipping lines in a file
by Limbic~Region (Chancellor) on Feb 17, 2004 at 22:36 UTC
    kvale,
    While this is a perfectly good solution, it may be an issue if the file in question is very large. In that case, instead of slurping the whole thing into memory it might be better to use a perl implementation of tac. If you need to manipulate the lines at all in addition to reversing them, you could always have a look at File::ReadBackwards

    For any other conversions of sed, there is always the s2p utility that ships with the core.

    Cheers - L~R

      Actually, I need it to swap lines Only if it matches a given pattern, like the sed example. I have some other lines Around the ones in the example which need to stay where they are. Where can I read more about s2p? I'm using perl on a network where they Think they've gotten rid of it-- everything I've tried so far works and compiles (when I get all the bugs fixed in my code) but I might not have everything. Thanks