use strict; use warnings; my $connect_string = "DBI:mysql:$CONFIG::database"; my $dbh = DBI->connect( $connect_string, $CONFIG::dbusername, $CONFIG::dbpassword, \%CONFIG::dbattr ); my $statement; my $result; { package CONFIG; %dbattr = ( PrintError => 0, ChopBlanks => 0, ); $database = "stuff"; $dbusername = "username"; $dbpassword = "password"; } my $insert = qq{ INSERT INTO storage ( url, altavista, yahoo, msn, teoma, google, alltheweb, Total, lastsearch, totalsearch ) values( '$url', '$altavista_results', '$yahoo_results', '$msn_results', '$teoma_results', '$google_results', '$alltheweb_results', '$total', '$time', '$total' ) }; my $update = qq{ UPDATE storage SET url = "$url", altavista = "$altavista_results", yahoo = "$yahoo_results", msn = "$msn_results", teoma = "$teoma_results", google = "$google_results", alltheweb = "$alltheweb_results", total = total +1, time = "$time" }; $statement = $update; $result = $dbh->do( $statement ); if ( ! defined $result ) { die "Fatal SQL error :\n$statement\n" . $dbh->errstr; } # If there were no rows affected by the update, execute the # insert if ( $result < 1 ) { $statement = $insert; $result = $dbh->do( $statement ); if ( ! defined $result ) { die "Fatal SQL error :\n$statement\n" . $dbh->errstr; } }