I'm working on a cook book in .txt format and I'd like to tag in xml the title,the ingredients and the procedure of each recipe.

The text look like this:

1.TITLE OF FIRST RECIPE abstract Ingredient 1. Ingredient 2. Ingredient n... Procedure... 2.TITLE OF SECOND RECIPE ...

1-I've tried to put all the file in one string and then apply the regex to it,but if the words matches,then I got printed all the text,and not just my line.

2-If instead I try to read the file line by line I can't search something like /[0-9]\. .*\n\n/ because I can't catch more than one \n.

3-Then I tried to create an array in this way

my @array=split (//,$linea);
but then I don't know how to handle it(I'm a perl beginner and this is my first post).

Here is my last attempt.All the \n are doubled so I've changed them with a single \n.

#!/usr/bin/perl use warnings; use diagnostics; use strict; my $text_file="cookbook.txt"; my $output="output.txt"; open(my $INPUT,"<",$text_file ) || die "Error: $!\n"; open(my $OUT,">",$output) || die "Error: $!\n"; my $linea = do { local $/; <$INPUT> }; $linea=~ s/[\r\n]/\n/g; $linea=~ s/\n\n/\n/g; if ($linea=~ //) { print $OUT $linea; } close $OUT; close $INPUT; exit;

So,I just want to catch(and print just what I've matched!) some text between more than one \n.

Thanks in advance,and sorry for my english.


In reply to 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.