Re: Extracting one record from multiple-records textfile
- From: pangj@xxxxxxxxxxxxx (Jeff Pang)
- Date: Wed, 28 Nov 2007 09:44:30 +0800
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. <giuseppegallone@xxxxxxxxx> 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: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/
- Follow-Ups:
- Re: Extracting one record from multiple-records textfile
- From: Giuseppe.G.
- Re: Extracting one record from multiple-records textfile
- References:
- Extracting one record from multiple-records textfile
- From: Giuseppe.G.
- Extracting one record from multiple-records textfile
- Prev by Date: Re: Extracting one record from multiple-records textfile
- Next by Date: Re: Extracting one record from multiple-records textfile
- Previous by thread: Re: Extracting one record from multiple-records textfile
- Next by thread: Re: Extracting one record from multiple-records textfile
- Index(es):