Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Split string after 14 Line Feeds?

by Cody Fendant (Friar)
on Dec 04, 2012 at 11:30 UTC ( #1007067=note: print w/replies, xml ) Need Help??


in reply to Split string after 14 Line Feeds?

Just because this solution hasn't been hinted at yet:

while (<DATA>) { chomp; if ( $. % 14 == 0 ) { print "$_ -- do something here\n"; } else { print "$_\n"; } } __DATA__ line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9 line 10 line 11 line 12 line 13 line 14 line 15 line 16 line 17 line 18 line 19 line 20 line 21 line 22 line 23 line 24 line 25 line 26 line 27 line 28 line 29 line 30

Don't forget this kind of solution will leave you with extra unprocessed lines whenever the total number of lines isn't a multiple of 14, so wrap those up after you're finished with the loop.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007067]
help
Chatterbox?
[ambrus]: "you are far more likely to be squished between two other dudes" => wait, really? aren't most planes, weighted by people traveling on it, so narrow that there are only two or three seats on each side of the one corridor, so only one third of the people ge
[ambrus]: t squished between two other people?
holli is about to take the first hit since a month and this weed is strong shit. Should my head explode, someone call 911.
[ambrus]: And even when I traveled on a big plane for a long flight, it had 3 seats, then corridor, then 4 seats, then corridor, then 3 seats, so less than half of the people sit between two other dudes.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2017-12-18 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (486 votes). Check out past polls.

    Notices?