perlquestion
avanta
Hi All,<br/><br/>
I am trying to read a log file one transaction (block of lines) at a time. Now I wish to deliver this data to two separate processes by forking. Following is the code I tried to come up with.
<code>
my $flag=0;
my $pid;
while ($record = $fp->getline())
{
if(flag == 0)
{
$flag=1;
$pid=fork();
}
else
{
if($pid == 0)
{
function1($record);
}
else
{
function2($record);
}
}
}
</code>
In the code "$fp->getline()" is reading the transactions and storing in "$record" in a loop and by conditional forking I transferred "$record" to two different functions in different processes. But here as you can see for first transaction the reading from log file is done only once but for subsequent transactions this is done twice as we have two processes at that moment.<br/><br/>
This is where my problem starts. I wish to read the log file only once and send the data to two different processes for processing. And, also the limitation is that I cannot read all the transactions in the log file at once and send it for processing, I have to read it transaction by transaction. <br/><br/>
An example of log file content can be:
<code>
Date: 2010-05-01
location: NZ
Date: 2010-05-02
location: AU
Date: 2010-05-03
location: IN
</code>
So now $record will have <br/><br/>
Date: 2010-05-01<br/>
location: NZ<br/>
<br/>
as first transaction and so on. <br/>
<br/>It would be great if any one can tell me how I can achieve my goal.<br/>
Thanks<br/>
AvantA