Even when the query is empty the If clause in the while loop will not print &quot;name NOT defined&quot;<br><br>I suspect this has something to do with fetchrow_array and using !defined() doesn&#39;t work.<br><br>==========================================================
<br><br>my $query = &quot;select deviceip, devicename from (select * from admDevice where admDevice.devicename like \&#39;%$_%\&#39;) as devi<br>&nbsp;&nbsp;&nbsp; ces, admSyslogSrc where devices.deviceId = admSyslogSrc.deviceId&quot;;<br>
<br>$sth = $dbh-&gt;prepare($query);<br><br>if( defined( $sth )) {<br>&nbsp;&nbsp;&nbsp; $sth-&gt;execute(&nbsp; );<br>}<br><br>while ( my ($hostint, $name) = $sth-&gt;fetchrow_array ) {<br>&nbsp;&nbsp;&nbsp; if ( !defined($name) ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;name NOT defined&quot;;
<br>&nbsp;&nbsp;&nbsp; } <br>