maybe something like this

# open file as usual # foreach line of the file # DON'T CHOMP, (still) if (/\(/) { # I have found a "(", this must be a title, so I: chomp; push @titles, $_; # now this is the more problematic part cause you need # to extend your search to several lines # but you are processing line by line, the idea is that # we have a title, now we stop and parse text. # 1- pick up all between ) and ( and save this to a $var # ie: with \).*?\( # unfinished yet, take a look to substr # 2 -split the different items in this text-block @texts = split /\n/, $var; pop @texts # the last value is the next title, # so we can discard it safely # we enter a inner loop for all items in the array while (@texts) {print $titles[-1] . '; '. $_} } else { next # this is not a title, whe forget this line } # end of the if-else block } # end of the foreach-block

This code is not complete, only a rough draft showing the idea: you have two problems here, 1) - chase the titles one by one (this should be very easy) and 2) - to enter a "inner parse mode" after a title was found, stop the hunting and process all text until the next title line"

Update: you need to wide the @texts array after each foreach pass, so insert a @texts = (); line just after # DON'T CHOMP


In reply to Re: Insert newline by pvaldes
in thread Insert newline by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.