Re: Extracting one record from multiple-records textfile
- From: krahnj@xxxxxxxxx (John W . Krahn)
- Date: Tue, 27 Nov 2007 18:07:53 -0800
On Tuesday 27 November 2007 11:29, Giuseppe.G. wrote:
Hello there.
Hello,
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?
# Set the Input Record Separator
$/ = "\nDOC-END\n";
while ( my $doc = <FILE_HANDLE> ) {
parsing function( $doc );
}
John
--
use Perl;
program
fulfillment
.
- 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: error on simple system command
- Previous by thread: Re: Extracting one record from multiple-records textfile
- Next by thread: about ( .)
- Index(es):