Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Do you know where your variables are?
 
PerlMonks  

Re: Sed to perl conversion-- flipping lines in a file

by thelenm (Vicar)
on Feb 17, 2004 at 22:35 UTC ( #329778=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Sed to perl conversion-- flipping lines in a file
Download Code
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://329778]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2014-04-19 20:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls