in reply to loading a .txe into a database
I'm sure that there are cooler ways to do it, but this one's pretty transparent.my @row; my $select = $dbh->prepare( ' SELECT COUNT(*) FROM games where gamename=? ' ); my $insert = $dbh->prepare( ' INSERT INTO games (gamename, gamedesc, gamecounter) VALUES (?, ?, ?) ' ); my $update = $dbh->prepare( ' UPDATE games SET gamedesc=? where gamename=? ' ); open (FILE, "<../data/games/descriptions.txt") or die $!; while (<FILE>) { chomp; my ($gamename, $gamedesc) = split /\t/; $select->execute($gamename); my $count; while( my $ref = $select-> fetchrow_arrayref() ) { $count = $ref->[0]; } if( $count == 0 ) { #a new game $insert->execute( $gamename, $gamedesc, 0 ); } else { $update->execute( $gamedesc, $gamename ); } } close (FILE);
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: loading a .txe into a database
by Nik (Initiate) on May 03, 2005 at 10:39 UTC | |
by Nik (Initiate) on May 03, 2005 at 11:04 UTC | |
by polettix (Vicar) on May 03, 2005 at 11:29 UTC |