我已将script1转换为script2以获得 db insert 语句。但是,我的 script2 会在一段时间后停止,就像我将脚本放入循环后内存不足一样。如果我只运行 script1 然后循环永远运行。我错过了什么?
脚本1
logupdate("${cid}_$mon$day${year}_${time}_${status}.csv",
"$uid|$ext||$cid|$did|$status\n");
# log to file
sub logupdate
{
my $log = shift;
unless (open(LOG, ">>$path$log"))
{
print STDERR "Can't write to $path$log: $!\n";
}
print LOG @_;
close LOG;
}
脚本2
{
my $filedata = "${cid}";
my $filename = "$status";
logupdate("${cid}", "$status");
}
# log to file
sub logupdate
{
my $filedata = shift;
my $filename = shift;
if ( not $dbh ) {
$dbh = DBI->connect( $url, $user, $dbpass );
sleep 6;
print "reconnecting to db.... Success!\n";
}
if ( not $filedata eq '') {
$sth = $dbh->prepare('INSERT INTO cliinfo (calltype, callno)
VALUES(?, ?)');
$sth->execute($filename, $filedata);
print "Inserting into db $filename:\t\t$filedata\n";
}
}