sub InsertMultipleValues { #----------------------------------------------------------- # Inserts contents of a hashref into the db table specified # (owes a lot to discussion in SOPW (which I looked for # just now but couldn't find, alas) #----------------------------------------------------------- my $dbh = shift; my $table = shift; my $Inserts = shift; my @cols = keys %$Inserts; my @vals = @$Inserts{@cols}; my $cols = join ',', @cols; my $places = '?,' x @vals; chop $places; my $sth = $dbh->prepare("INSERT INTO $table ($cols) VALUES ($places)") or die $dbh->errstr; $sth->execute(@vals) or die $dbh->errstr; }