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


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

Just to be tricksy, here's another way to do it (originally by Eugene van der Pijll in the Santa Golf on the Fun With Perl list):

#!/usr/bin/perl -p $\=$_.$\}{

-- Mike

--
XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
-- grantm, perldoc XML::Simpler

Replies are listed 'Best First'.
Re: Re: Sed to perl conversion-- flipping lines in a file
by NovMonk (Chaplain) on Feb 19, 2004 at 22:02 UTC
    This is very cool, Mike. I tried to modify it so that it would only flip lines that met certain conditions (like my sed example above) and went down in flames. Is there a way to get this code to Only swap lines around if the lines contain the following text: '1' or '2' or '3' and to otherwise print the lines in the original file order?

    What I really want to get to is something that will convert this highlighted text in vi editor (alas, I am so far in the dark ages my company has not even Heard of Vim, but would probably burn me at the stake for speaking of it):

    Line 1 Line 2 Line 3 flip line '1' flip line '2' flip line '3' Line 4 to: Line 1 Line 2 Line 3 flip line '3' flip line '2' flip line '1' Line 4

    Does this make more sense to anyone?

    Thanks very much for the (hopefully) gentle correction and admonishment, Monks.