perl script added database insert statement stop after some time while in a loop -


i've converted script1 script2 have db insert statements. script2 stops after time run out of memory after putting scripts in loop. if run script1 loop run forever. missing?

script1

logupdate("${cid}_$mon$day${year}_${time}_${status}.csv",        "$uid|$ext||$cid|$did|$status\n");  # log file sub logupdate {        $log = shift;        unless (open(log, ">>$path$log"))        {                print stderr "can't write $path$log: $!\n";        }        print log @_;        close log; } 

script2

{        $filedata = "${cid}";                                   $filename = "$status";                              logupdate("${cid}",  "$status"); }  # log file sub logupdate {     $filedata = shift;     $filename = shift;      if ( not $dbh ) {         $dbh = dbi->connect( $url, $user, $dbpass );         sleep 6;     print "reconnecting db.... success!\n";     }     if ( not $filedata eq '') {         $sth = $dbh->prepare('insert cliinfo (calltype, callno)               values(?,      ?)');     $sth->execute($filename, $filedata);     print "inserting db $filename:\t\t$filedata\n";     } } 

if not using $dbh global variable initialize $dbh 'my';

my $dbh; 

disconnect db connection within function;

$dbh->disconnect(); 

to safer, @ end of function assign undef $dbh variable;

$dbh = undef; 

Comments