in reply to Is this too clever? (or, stupid DBI tricks)
my ($sum) = $sth->fetchrow_array;
Or, if you have your SQL in a variable...
my ($sum) = $dbh->selectrow_array( $sql, undef, $foo, $bar, $rat );
DBI has all kinds of good stuff.
Update: When there is no result, $sum will be undef. You can do $sum ||= 0 (or $sum //= 0 in Perl 5.10) to avoid generating warnings about this later.
|
|---|