Hello,
Just show another way to do it.
use strict;
local $/="\n\n";
while(<DATA>) {
next unless /^DOC-START\n(.*?)\nDOC-END$/sm;
my $content = $1;
parse($content);
}
sub parse {
my $c = shift;
print length($c),"\n";
}
__DATA__
DOC-START
content of the document
DOC-END
DOC-START
some text
DOC-END
DOC-START
rtreytgfbvb
DOC-END
DOC-START
sdfdf fdff ee
DOC-END
__END__
On Nov 28, 2007 3:29 AM, Giuseppe.G. <[EMAIL PROTECTED]> wrote:
> Hello there. I'm a real beginner and I was wondering if you could be
> so kind to help me on this.
> I have a text file, containing a number of varying length documents,
> all tagged with DOC-START and DOC-END, structured as follows:
>
>
> DOC-START
> content of the document
> DOC-END
>
> DOC-START
> some text
> DOC-END
>
> DOC-START
> rtreytgfbvb
> DOC-END
>
> DOC-START
> sdfdf fdff ee
> DOC-END
>
> ...
>
> I need to take every document and pass it to a parsing function, that
> accepts a file with *a single* document, that is
>
> DOC-START
> some text
> DOC-END
>
> My file contains lots of these records, so picking each document and
> writing it into a new file is not an option. How can I extract the
> documents one at a time from the file? Is it possible e.g. to put one
> such record iteratively into a temporary file and pass this to the
> parser?
>
> Your help would be greatly appreciated.
>
> Thanks
> Giu
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/