Maybe this is a little OT but since I am a beginner @ perl, I thought that I
would post it!

 

So, I am trying to move data from one sql table to another table called
logs_archive. It seems that I am running into some problems with memory as I
am moving this much data from one table to another. This is just syslog data
but we need to archive it in some way. Can anybody give any advice? Code is
below.

 

 

 

 

$sth = $dbh->prepare( "select * from logs where ( timestamp <=
'$start_date$start_time' )" );

$sth->execute();

 

while ( my $ref = $sth->fetchrow_hashref() ) {

            $msg_field = $ref->{'msg'};

            if ( $msg_field =~ /\'/ ) {

                        $msg_field =~ s/\'/\\'/g;

            }

            $string = "INSERT INTO logs_archive ( timestamp, host, facility,
priority, level, tag, date, time, program, msg ) VALUES (
'$ref->{'timestamp'}', '$ref->{'host'}', '$ref->{'facility'}',
'$ref->{'priority'}', '$ref->{'level'}', '$ref->{'tag'}', '$ref->{'date'}',
'$ref->{'time'}', '$ref->{'program'}', '$msg_field' )";

            $dbh->do( $string );

}

 

$string_delete = "delete from logs where ( timestamp <=
'$start_date$start_time' )";

Reply via email to