Ahh yes, what I commonly call the "null vs. 0 gank"... The perl syntax
allowing you to run alternate code during an assignment if the return
value of the assignment is 0 OR undef.

I'm assuming you only want to call dbError if the result from
selectrow_array() is undef (an actual error) and not if the result from
selectrow_array() was that count() == 0.

You should replace:

$expire  = $dbh->selectrow_array($sqlquery) or dbError();

with 2 lines:

$expire = $dbh->selectrow_array($sqlquery);
dbError() unless defined($expire);

IMHO just one of those places it's best _not_ to use a nice compact
perlism to reduce the size of your code.

Steve



> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, September 22, 2001 7:38 PM
> To: [EMAIL PROTECTED]
> Subject: Avoid Error if no results
> 
> 
> Hi All,
> 
> this one seems to puzzle me on how to avoid an unnecessary db 
> error. I need to
> run a tally count on a couple tables, and if there isn't any 
> data in the table
> it displays the dbError, altho there isn't technical any 
> syntax error in the
> query other then no return or results. 
> 
> my $active = 0;
> my $expire = 0;
> 
> $sqlquery = qq|SELECT COUNT(m.memid) FROM members m,payhistory p 
>                WHERE p.active = 'Y' AND p.memid = m.memid|;
> $active = $dbh->selectrow_array($sqlquery) or dbError();
> 
> $sqlquery = qq|SELECT COUNT(*) FROM expired WHERE expdate < 
> CURDATE()|;
> $expire  = $dbh->selectrow_array($sqlquery) or dbError();
> 
> Is this way to avoid the dbError() if the query returns no 
> results(which would
> indicate a '0' tally.
> 
> thx's
> 
> Mike(mickalo)Blezien
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> Thunder Rain Internet Publishing
> Providing Internet Solutions that work!
> http://www.thunder-rain.com
> Tel: 1(225)686-2002
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> 
> 

Reply via email to