[EMAIL PROTECTED] wrote:

> Hi all:
>
> This newbie is back looking for some hints on how to handle this problem
> in processing a file that has multiline records that look something like
> this:
>
> Name:  Joe Blow
> DataField1:  xxxxx
> DateField1: 07/07/77
> DataField2: xxxxx
> DateField2: 12/07/03
>
> Name:  Fi Doe
> DataField1:  xxxxx
> DateField1: 08/08/88
> DataField2: xxxxx
> DateField2: 12/12/03
>
> etc.
>
> There is an empty line that separates each record.   I need to extract the
> records that meet certain criteria.   I would really like to know how to
> do this in Perl.
> ...

> Until then, here's what I was thinking to do.  What I thought I would do
> is try to read each line of one record into an array or hash, t

Why each line?  It's pretty clear that the lines are not really the logical
strucure of the records in this file.  You do have to input the lines one at a
time, since that is the way Perl generally reads, but that doesn't mean that
the lines should go into a program structure without filtering.  During the
input, you actuall have more context than you would if lines become simply
elements of an array.

Unless I'm missing something here, your example indicates that each data field
spans more than one line.  unless those x's are meant literally.  I would
suggest that you should do some processing for each data field, over however
many lines of input it takes, so that the fields each have an element to
themself.  Of course an excerpt as opposed to a context-deprived schematic
would help us undestand what is actually in the data.  That is a very
important consideration when it comes time to choose a processing method.

> hen use a
> conditional to determine if that record meets the desired criteria.  If it
> meets the criteria, write out this record to another  file and then read
> in the next record.  If the record doesn't meet the criteria, read in the
> next  record.  I would keep doing this until EOF.
>
> I think I can handle the conditional stuff, but what I don't know how to
> do is read in each line of the record and stop reading when I hit the
> empty line so that I can do the conditional stuff.

I would start with making a very clear record structure specification

Can you send us an example of the real data?  Taking meaning out of data is
counter -productive to solving problems of how to handle it.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to