If I follow you correctly, you want to read in the raw text, xml tag the components and print it back out?

You have a fairly loose 'format', but if it looks like the example you posted, maybe there are a few workarounds:

use strict; use warnings; ## buffer for holding each Recipe my @buffer; ## read data while(<DATA>){ if (m/^\d+\.\U.+\E$/){ ## begins with a number and is in all upper case ## must be a title, so process what we already have process_buffer(\@buffer); ## reset buffer @buffer = ($_,); } else { push @buffer, $_; } } ## don't miss the last one! process_buffer(\@buffer); ### SUBS ### sub process_buffer{ ## collect buffer my @buffer = @{$_[0]}; ## need at least two lines... return 0 unless (scalar@buffer > 1); ## process it ... } __DATA__ 1.TITLE OF FIRST RECIPE abstract Recipe 1. Recipe 2. Recipe ... Procedure...

I'll leave it up to you how to further break down the sections, but hopefully this is a start.

Are you familiar with the various XML handling modules on CPAN? : XML (I am no expert, but XML::Twig seems popular here, but XML::Quick looks useful for you).

If you want more help on regexes, check out the perldoc tutorials : perlretut

Hope this helps, keep us posted on your progress!

Just a something something...

In reply to Re: Regexp and reading a file n-lines at time by BioLion
in thread Regexp and reading a file n-lines at time by epimenidecretese

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.