Click to See Complete Forum and Search --> : Is there a simple solution to this?


Takshaka
09-10-2004, 08:49 PM
I have a script which processes email and enters data into a database. The emails being processed are formatted
Field1: data
Field2: data
etc with each Field starting on a new line.

Most fields are being processed correctly but fields which run onto more than 1 line are not being correctly processed.

The code which processes the fields is

if (/Field1: /) { $field1 = $'; }

How do I change this to include data on the next line(s) or to include all data between "Field1:" & "Field2:" ?

Thanks

silent11
09-10-2004, 10:01 PM
That's a tough one. I had that problem once before too. Let me see if I can dig up how I solved it.

chrisranjana
09-13-2004, 04:35 AM
try

if (/Field1: /s) { $field1 = $'; }


if (/Field1: /sgi) { $field1 = $'; }

Takshaka
09-13-2004, 11:54 AM
Thanks for the suggestion but it doesn't seem to make any difference.

jknox
09-16-2004, 02:27 PM
How about using a temp variable for the data.

Loop through the data until you find a line that starts with 'Fieldx'
Set $lastField to 'Fieldx'
Set $data to the rest of the line
Loop and read the next line
If it starts with 'Fieldx' then
set $Fieldx to $data ($Fieldx is determined by the contents of $lastField)
set $lastField to ''
set $data to ''
otherwise
set $data to $data + the current line

Sorry, I've been out of Perl for too long to code this on the fly -- give me a couple of weeks to get back up to snuff. :^)

Hopefully it gives you enough logic to get your project off the ground.

Scriptage
09-30-2004, 06:24 AM
A better solution would be to convert your database to a dbm file. This is by far more effective than what you are doing.