Hi All,
Question 1: I have a huge text file (50MB approx) and I need to parse it once in a process and pass the duplicate content to another one. I have a sample code to parse a file but how can I duplicate the output is where I am stuck.
sub processInputFiles
{
<----doing something--->.....
......
LogInfoMsg("Processing $file Started");
if ($f_type eq ".gz")
{
$fp= new IO::Zlib($working_file,"rb");
$tfp= new IO::Zlib($working_file,"rb");
}
elsif ($f_type eq ".log")
{
$fp= new IO::File($working_file,"r");
$tfp= new IO::File($working_file,"r");
}
else
{
LogCriticalMsg("Unsupported file_type($f_type), Skip parsing $
+file.");
return;
}
if (! $fp)
{
# if it fails for some reason, rename to its original name.
rename ($working_file, $file);
LogCriticalMsg("Open input file $file failed. $!");
}
else
{
if(grep m/[\r]/,$line)
{
IO::File->input_record_separator("\r\n\r\n");
}
else
{
IO::File->input_record_separator("\n\n");
}
close($tfp);
}
while ($record= $fp->getline())
{
<---parsing file per record---->
}# end of while
}
}
<----doing something--->
the code may have errors but what I want is the concept to duplicate data in two or more processes (forking) so that I parse the input file only once. The input file can be huge so cant store in some variable or array or hash.
Question 2: which will be faster parsing the input huge file in two different processes or parsing it once and send the data to different processes record by record?
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.