in reply to A more elegant solution?

Or, use the set notation :
my $sql = "INSERT INTO $table_name SET "; for (keys %hash) { $sql .= "$_ = '$hash{$_}' ,"; } chop $sql;
Ought to do it. It is better to call $dbh->quote($hash{$_}) to quote the string value if you have that handle.
--
Brovnik

Replies are listed 'Best First'.
Re: Re: A more elegant solution?
by htoug (Deacon) on Aug 19, 2001 at 19:15 UTC
    Not alway legal.

    Accourding the the databases I use, SET is only allowd in an UPDATE statement.

    You should definitely always use $dbh->quote() insted of just adding '-characters. The latter will fail if the string contains any 's (if you get my meaning).