Skip to content

Commit

Permalink
Added a script for reading in questions automatically from a txt and …
Browse files Browse the repository at this point in the history
…added some more comments
  • Loading branch information
LindseyB committed Feb 27, 2009
1 parent 11670d1 commit cc7c892
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions DatabaseCreate.pl
@@ -0,0 +1,34 @@
#!/usr/bin/perl -w

#################################################################################
# DatabaseCreate.pl #
# #
# will read in questions from questions.txt and dump them into the database #
#################################################################################


use DBI;
use strict;

my $dbh = DBI->connect("dbi:SQLite:dbname=Trivia.db","","") or die "Can't open DB: $!";

open(DAT, "questions.txt") || die("Could not open file!");
my @raw_data=<DAT>;
close(DAT);

print "Starting transfer...\n";

foreach my $question (@raw_data)
{
chomp($question);
(my $q, my $a) = split(/\*/, $question);
$q = $dbh->quote($q);
$a = $dbh->quote($a);

my $sql = qq{INSERT INTO questions (question,answer) values($q, $a)};
print "About to execute [$sql]\n";

$dbh->do($sql) or die $dbh->errstr;
}

print "Transfer complete.\n";

0 comments on commit cc7c892

Please sign in to comment.