Perl DBI insert of hash
This might be a good candidate to use SQL::Abstract in, as per DBIx::Class.



sub insert {
    # insert takes ( $table, \%fieldmap )
    my $sql = SQL::Abstract-&gt;new();
    my ( $query, @binds ) = $sql-&gt;insert( @_ );
    $dbh-&gt;prepare($query)-&gt;execute(@binds);
    return $dbh-&gt;last_insert_id(undef, undef, undef, undef);
}


This gives you a few easy features that may come in handy in the future
if you change your database, like:


easily change quoting character for tables/fields
guard against injection abuse in user-specified key names, because your code currently assumes all keys will be safe. But this will not necessarily be true, and is a vulnerability target even under taint