Gossamer Forum
Home : General : Databases and SQL :

print out select result (empty set)

Quote Reply
print out select result (empty set)
When do a select, the query result is "empty set"

how to have perl to identitfy the returned result as "empty set [/b]" and have it

print out a customized message, say" no record matching ".



Thanks

Last edited by:

courierb: May 16, 2002, 5:56 AM
Quote Reply
Re: [courierb] print out select result (empty set) In reply to
$sth->rows or error();

or....

my $hashref = $sth->fetchrow_hashref;

scalar %$hashref or error();

or...

my @array = $sth->fetchrow;

scalar @array or error()

etc etc....
Quote Reply
Re: [Paul] print out select result (empty set) In reply to
Thanks, it works, althrough i do not know the code meaning.



What is "scalar %$hashref" meaning?
Quote Reply
Re: [courierb] print out select result (empty set) In reply to
It checks if the hashref is empty or not.

eg....

my $hashref = { a => 'b' };

print scalar %$hashref ? 'YES' : 'NO';

That would print YES.

my $hashref = {};

print scalar %$hashref;

That would print NO.

~~ %$hashref will do the same. eg..

print ~~ %$hashref ? 'YES' : 'NO';

Last edited by:

Paul: May 17, 2002, 7:05 AM