I have a program which loops over an input file, one line at a time. It does some comparisons of this one line to a lookup file and then writes out the best match to a file.

However, before it continues to the next line in the file, it needs to make a single simple database commit to SQLite based on in-memory values - nothing new needs to be computed.

I am running Perl 5.8.8 under Cygwin.

My goal is to take advantage of the fact that this machine has two CPUs - it is an Intel Centrino Duo. I want the database commit to happen on the second CPU while the machine goes ahead and reads the next line.

What sort of module or function would be best for this purpose?

while (<I>) { my $line = $_; my @bucket = $bucket->based_on($line); # Data::Bucket my @acct_vals; for (@bucket) { # %hash = calculate based on input and bucket value push @acct_vals, \%hash; } next unless @acct_vals; @acct_vals = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, $_->{dist} ] } @acct_vals; # write $acct_vals[0] and $line out to file # ** Help needed ** # write out to SQLite but without holding up # next loop iteration my @dump ; for my $acct_val (@acct_vals) { last if $acct_val->{dist} > $match_threshold * 1.5 ; push @dump, $acct_val; } my $d = Data::Dumper->new([\@dump], ['dump']) ; $d->Purity(1)->Terse(1)->Deepcopy(1); # DBIx::Simple by Juerd Waalboer $dbs->query('INSERT INTO addresses VALUES (??)', $acct_name, $clean_acct_name, $d->Dump); # *** end Help Needed unless (++$counter % $report_very) { warn "$counter in $now"; # Time::Lapse by Scott Godin } }
I have beheld the tarball of 22.1 on ftp.gnu.org with my own eyes. How can you say that there is no God in the Church of Emacs? -- David Kastrup

In reply to Taking advantage of dual processors [tag://parallel,cygwin,multi-core,fork,i/o] by metaperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.