http://qs321.pair.com?node_id=455559

Nik has asked for the wisdom of the Perl Monks concerning the following question:

This is the best i can do with my games.pl script to load the game, description and times downloaded from a .txt file to database. Can you suggest something better?
my $dbh = DBI->connect('DBI:mysql:nikos_db', 'root', 'censored') or {R +aiseError=>1}; #===================================================================== +========== my @row; my $insert = $dbh->prepare( "INSERT INTO games (gamename, gamedesc, ga +mecounter) VALUES (?, ?, ?)" ); my $update = $dbh->prepare( "UPDATE games SET gamedesc=? where gamenam +e=?" ); open (FILE, "<../data/games/descriptions.txt") or die $!; while (<FILE>) { chomp; my ($gamename, $gamedesc) = split /\t/; $insert->execute( $gamename, $gamedesc, 0 ); if ($DBI::err) { print "Error on INSERT $gamename: $DBI::errstr\n"; $update->execute( $gamedesc, $gamename ); if($DBI::err) { print "Unable to UPDATE $gamename: $DBI::errstr\n"; } } } close (FILE);
I just need some way to update the mysql table if a gamename exists in the mayswl table games or insert a new one if it does not.