#!/usr/bin/perl use strict; use warnings; use DBI; use YAML qw ( LoadFile ); my $poll_file = shift @ARGV or die "no file no poll!\n"; my ($poll, $questions) = LoadFile($poll_file) or die "Sorry, no question-file!\n"; my $config = LoadFile('conf/conf.yaml'); my $sql_create = qq{ CREATE TABLE $poll->{identifier} ( ID bigint(20) unsigned NOT NULL auto_increment, Zeitstempel timestamp(14) NOT NULL, }; $sql_create .= join("\n", map { " $_->{id} smallint(5) unsigned default '3'," } @$questions); $sql_create .= "\n primary key (ID))\n TYPE=MyISAM;"; my $dbh = DBI->connect ("DBI:mysql:host=$config->{db_host};database=$config->{db_database}", $config->{db_user}, $config->{db_pass}, {PrintError => 0, RaiseError => 1}) or die "Failed to connect via DBI:$!\n"; $dbh->do($sql_create) or die "$sql_create: $dbh->errstr\n"; exit;