title: How do I insert values from a hash into a database using Perl's DBI module?
body: <p>I need to insert values from a hash into a database. Following is the code template I have to insert values in table1 column <em>key</em> and <em>value</em>:</p>
  
  <pre><code>use DBI;
  use strict;
  
  %hash; #assuming it already contains desired values
  my $dbh = DBI-&gt;connect(
        "dbi:Sybase:server=$Srv;database=$Db", 
        "$user", "$passwd"
  ) or die sprintf 'could not connect to database %s', DBI-&gt;errstr;
  my $query= "Insert INTO table1(key, values) VALUES (?,?) ";
  my $sth = $dbh-&gt;prepare($query) 
      or die "could not prepare statement\n", $dbh-&gt;errstr;
  $sth-&gt; execute or die "could not execute", $sth-&gt;errstr; 
  </code></pre>
  
  <p>I know how to insert values using array i.e use <code>execute_array()</code>, but do not know how to insert values present in <code>%hash</code> in table1.</p>
  
  <p>Any suggestions? </p>