title: How do I know how many rows a Perl DBI query returns?
body: <p>I'm trying to basically do a search through the database with Perl to tell if there is an item with a certain ID. This search can return no rows, but it can also return one.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>my $th = $dbh-&gt;prepare(qq{SELECT bi_exim_id FROM bounce_info WHERE bi_exim_id = '$exid'});
  $th-&gt;execute();
  if ($th-&gt;fetch()-&gt;[0] != $exid) {
          ...
  </code></pre>
  
  <p>Basically, this tries to see if the ID was returned and if it's not, continue with the script. But it is throwing a Null array reference error on the <code>$th-&gt;fetch()-&gt;[0]</code> thing.
  How can i just simply check to see if it returned rows or now?</p>