Hello monks,
I have a relatively large datafile (100MB or so). All lines from this file are to be processed and dumped to MySQL table, **except** those lines that are already in MySQL table.
For example, ids F1,FTDR,RJIER,KERF are present in MySQL and I dont want to process lines from the datafile beginning with these IDs. I do the following at this time:
# populate DISTINCT ids from table into a variable
# separated by pipe symbol; variable looks like below
# and contains 15000 distinct ids
$compare = "F1|FTDR|RJIER|KERF...."
# open the file and loop
open (MFIL,"<datafile") or die ("ouch");
while ($lines = <MFIL>)
{
chomp ($lines);
$lines =~ m/^$compare/o && next;
print $lines,"\n";
}
close (MFIL);
This takes over 5 minutes on a 384MB RAM box running FC4 kernel 2.6.11 and Perl v.5.8.6.
If I process all lines from the file and handle MySQL errors (of duplicacy) manually, the file takes about 3 minutes. I am sure there should be a better/faster method to doing this. Please feel free to suggestion me options.
Thank you, all.
Regards,
Chirag Shukla
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.