Hi All,
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.
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);
}
}
}
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.
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.
An example of log file content can be:
Date: 2010-05-01
location: NZ
Date: 2010-05-02
location: AU
Date: 2010-05-03
location: IN
So now $record will have
Date: 2010-05-01
location: NZ
as first transaction and so on.
It would be great if any one can tell me how I can achieve my goal.
Thanks
AvantA
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.