epimenidecretese has asked for the wisdom of the Perl Monks concerning the following question:
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
but then I don't know how to handle it(I'm a perl beginner and this is my first post).my @array=split (//,$linea);
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.
|
|---|