perl Fock & DBI problem

M

Michael

Hi, thank you for taking your previous time to read the following
problem that I face.

I'm trying to create multiple child process and TESTCODE 1 work fine,
however if I try to connect to MYSQL (TESTCODE 2) before calling the
subroutine "testmail2", I would never get the expected result. I would
appreciate if anyone would be so kind to help me solve the problem or
suggest an alternative solutions. My objective is to create mutiple
child process using the data pull-out from the MYSQL.

Thanks.
Michael


TESTCODE 1
===========
@names=("Sandy", "Sally", "Sarah", "Sue","imgoingcrazy","WHYYYYYYY");
&testmail2(@names);

sub testmail2
{
#databae,content,mailing counter
my @sqlarray = @_;
my $item;
my $cpro=0;
my $arraylen = int @sqlarray;

foreach $item(@sqlarray)
{
my $cpid = fork();
die unless defined $cpid;
if (! $cpid)
{
print "$item<br>\n";
srand();
sleep(int rand(1) + 1);
exit(0);
}
}

#wait for all child process ended
while ((my $cpid = wait()) != -1)
{
$cpro++;
if($cpro >=$arraylen)
{
print "Proceeding to next mailing. Please Wait<br>\n";
last;
}
else
{
print " Entered $cpro<br>";
}
}

return 1;
}

Good result 1
==============
Sandy
Sally
Sarah
Sue
imgoingcrazy
WHYYYYYYY
Entered 1
Entered 2
Entered 3
Entered 4
Entered 5
Proceeding to next mailing. Please Wait



TESTCODE 2
===========

my $dbh = &db_connect($dsn, $user, $password,{InactiveDestroy=>1});
my $sth = $dbh->prepare ("SELECT * FROM $table");
$sth->execute() || quit();

my $hashref;
my $tmpstring;
while ($hashref = $sth->fetchrow_hashref())
{
$tmpstring = "$hashref->{'name'}";
print $tmpstring;
}
$sth->finish();
$dbh->disconnect;

@names=("Sandy", "Sally", "Sarah", "Sue","imgoingcrazy","WHYYYYYYY");
&testmail2(@names);

Fail result 2
=============
Sandy
Sally
Sarah
Sue
imgoingcrazy
WHYYYYYYY
DBI Handle has 1 uncleared child handles. Attempt to free non-existent
shared string. Attempt to free non-existent shared string. Attempt to
free non-existent shared string. Attempt to free non-existent shared
string. dbih_clearcom (h 0x1f35e2c, com 0x352263c): FLAGS 0x11: COMSET
Warn TYPE 2 PARENT DBI::dr=HASH(0x1f35e5c) KIDS 1 (0 Active) IMP_DATA
HASH(0x1f35d6c) in 'DBD::mysql::db' Attempt to free non-existent
shared string during global destruction.
Entered 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top