<html>
<body>
<font size=3>At 04:51 PM 10/17/2006, CaptNemo wrote:<br>
<blockquote type=cite class=cite cite="">Why is it so hard to check for
null values in perl!?!?!</font></blockquote><br>
I confess to wanting the smallest set of things to remember:<br><br>
&nbsp;
exists<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>
&nbsp;&nbsp;&nbsp; - test whether array or hash element is 'present'<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( exists
$lotto{23_31_07_42_18_05} ) { die &quot;rich&quot;; }<br><br>
&nbsp; defined&nbsp; - is the value 'something' or the unique value
undef<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( ! defined
$systolic_reading ) { warn &quot;dial 911&quot;; }<br><br>
&nbsp; length&nbsp;&nbsp;&nbsp; - is the value 'empty'?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( length $speech ) { print
&quot;They said '$speech'\n&quot;; }<br><br>
&nbsp; 'truth'&nbsp;&nbsp;&nbsp;&nbsp; - various shades of yes, a couple
ways to say no<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( $answer ) { print
&quot;Some kinda yes ('$answer'); }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
else&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{ print &quot;Some kinda no&nbsp; ('$answer'); }<br><br>
It easily gets more complicated from there
(Scalar::Util::looks_like_number() anyone?) but these are the four tests
to start with.&nbsp; Once you've looked these up in perlfunc (especially
see the discussion of exists) and the discussion &quot;Scalar
values&quot; in perldata you will no longer (cough) be (hack)
mystified... (gack)<br><br>
<blockquote type=cite class=cite cite=""><font size=3>Two
situations:<br>
1) checking is a variable is empty:</font></blockquote>[snip]<br>
<blockquote type=cite class=cite cite=""><font size=3>2) checking to see
if command line args were present:</font></blockquote>[snip]<br>
</body>
</html>