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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|