in reply to MultiThreaded Program in perl
Simplistically:
#! perl -slw use strict; use threads; use Thread::Queue; use DBI; our $N //= 4; sub child { my $Q = shift; while( my $work = $Q->dequeue ) { for my $thing ( @{ $work } ) { ## process data items } } } my $Q = new Thread::Queue; my @kids = map threads->create( \&child, $Q ), 1 .. $N; my $dbh = DBI->connect( ... ); my $sth->prepare( ...SQL HERE... ); while( my $ref = sth->fetch_* ) { $Q->enqueue( share_clone( $ref ) ); } ### Assume exiting the loop above means no more data $dbh->disconnect; ## tell the kids to die $Q->enqueue( ( undef ) x $N ); ## And wait for kids to clean up $_->join for @kids;;
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom