Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Split string after 14 Line Feeds?

by AnomalousMonk (Abbot)
on Dec 04, 2012 at 09:27 UTC ( #1007039=note: print w/ replies, xml ) Need Help??


in reply to Split string after 14 Line Feeds?

An approach using split (although conceptually similar to tye's) and splitting on groups of three lines because fourteen lines necessitates a very tedious example.

>perl -wMstrict -le "my $s = qq{foo \n bar \n baz \n fee \n fie \n foe \n aa \n bb \n cc \n}; print qq{[[$s]]}; ;; my @fields = split m{ (?: [^\n]* \n){3} \K }xms, $s; print qq{[[$_]]} for @fields; " [[foo bar baz fee fie foe aa bb cc ]] [[foo bar baz ]] [[ fee fie foe ]] [[ aa bb cc ]]

Update: Also tested/works in cases in which: last 'line' does not end in newline; exactly 3 lines processed; fewer than 3 lines processed; lines consist only of newlines; etc. – I think, in fact, all possible cases.


Comment on Re: Split string after 14 Line Feeds?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-12-29 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (191 votes), past polls