NovMonk has asked for the wisdom of the Perl Monks concerning the following question:
In my searches of regexp and Perl, I am not finding the answer to this-- is it possible to flip the order of lines based on their matching a given pattern? What I have in mind is this-- you have a file with the follwing contents:
1. text'1' 2. text'2' 3. text'3' ...
With sed, you could reverse the order of the lines thus:
/'1'/{ h d } /'2'/G /'2'/{ h d } /'3'/G /'3'/{ h d }
and end up with the file
3.text'3' 2.text'2' 1.text'1'
Is there a similar capability with Perl? I was working earlier today on making a program interactive with vi (see my earlier question), and this is a similar thing-- I need it to do this within a "while" construction and spit out all the lines back into the file I'm editing when I'm done. Can this be done?
Thanks.
|
---|