perl Fock & DBI problem

Discussion in 'Perl' started by Michael, Apr 26, 2004.

  1. Michael

    Michael Guest

    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
     
    Michael, Apr 26, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ulloa
    Replies:
    1
    Views:
    537
    Juha Laiho
    Jul 22, 2004
  2. Jerome Hauss
    Replies:
    0
    Views:
    181
    Jerome Hauss
    Oct 13, 2004
  3. Asby

    Mason, DBI, and DBI::Pg

    Asby, Jul 24, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    185
  4. Tim Haynes
    Replies:
    3
    Views:
    147
    Ron Reidy
    Sep 13, 2003
  5. Jonas Andersson

    Perl, DBI, localhost problem

    Jonas Andersson, Jan 30, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    102
    Paul Lalli
    Jan 30, 2004
Loading...

Share This Page