# some sample data. my %msgdata = ( messageid => $next_messageid, quoteid => $quoteid, body => $q_body, viewed => 0, timestamp_m => "CURRENT TIMESTAMP" ); # you can do a sort here if you care about the order # of the keys. my @keys = keys %msgdata; # uncomment this if you want to exclude all pairs # that have no value. #@keys = map {defined($msgdata{$_})? $_ : ()} @keys; # get all my values in the same order as my keys. my @values = @msgdata{@keys}; # replace any undefined values with "NULL". # Comment this out if you're excluding these above. # Note: if you're using $dbh to quote your values # then use $dbh->quote($_) for the true option @values = map {defined($_)? $_ : "NULL"} @values; # my sql statement. my $sql = "INSERT INTO msg ( " . join (",\n", @keys) . ") " . "VALUES " . join (",\n", @values); # or with DBI: (but not so good for printing) # you don't need to use the $dbh->quote above if # you use this. my $sql2 = $dbh->do( "INSERT INTO msg ( " . join (",\n", @keys) . ") " . "VALUES " . substr(("?,\n" x @values), 0, -2), undef, @values); #### insert($table, @keys, @values); # or possibly insert($table, $data_ref); # and definately $data_ref = select($table, $conditions_ref, $desired);