in reply to swapping lines that match a condition
Sounds like a job for regular expressions:
Grab the chunks and swap the #2 and 4 captures for the replace.$stuff =~ s/(frontStuff)(stuffToMove1)(middleStuff)(stuffToSwap2)(endi +ngStuff)/$1$4$3$2$5/;
PS: This would require multi-line match mode, given your input data; the "middlestuff" would be a newline.
An alternative way to do it, given the regularity of your data, might be to save each record into a hash, then print the hash values back out in whichever order you like. Useful if you're not totally sure of your data, and could be used to remove duplicates or fill in missing fields quite easily.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: swapping lines that match a condition
by TheBigAmbulance (Acolyte) on Sep 10, 2009 at 15:00 UTC | |
by bv (Friar) on Sep 10, 2009 at 16:56 UTC |