in reply to Determining if a DBI SELECT comes back empty

If you just need to know if there are any results but don't need to fetch them, use SELECT COUNT(*). If you need to both read any results and do something if nothing was read, then you can use a flag to signal when you read anything:
$sth->execute(); my $count = 0; while (my $row = $sth->fetchrow_arrayref()) { process_row($row); $count++; } unless ($count) { do_something_else(); }

Replies are listed 'Best First'.
Re: Re: Determining if a DBI SELECT comes back empty
by spacewarp (Pilgrim) on Dec 05, 2003 at 22:08 UTC
    Beautiful! Now that's the level of elegance I like to use, and I'm embarassed that I couldn't think of something this simple myself. 8)

    Thanks to everyone else as well.. you've added to my toolbox 8)

    Spacewarp

    DISCLAIMER:
    Use of this advanced computing technology does not imply an endorsement
    of Western industrial civilization.