title: How can I fetch a single count value from a database with DBI?
body: <p>The following code seems to be just too much, for getting a single count value.
  Is there a better, recommended way to fetch a single COUNT value using plain DBI?</p>
  
  <pre><code>sub get_count {
     my $sth = $dbh-&gt;prepare("SELECT COUNT(*) FROM table WHERE...");
     $sth-&gt;execute( @params );
     my $($count) = $sth-&gt;fetchrow_array;
     $sth-&gt;finish;
  
     return $count;
  }
  </code></pre>
  
  <p>This is shorter, but I still have two statements.</p>
  
  <pre><code>sub get_count_2 {
     my $ar = $dbh-&gt;selectall_arrayref("SELECT ...", undef, @params)
     return $ar-&gt;[0][0];
  }
  </code></pre>