<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>
exists<x-tab> </x-tab>
- test whether array or hash element is 'present'<br>
if ( exists
$lotto{23_31_07_42_18_05} ) { die "rich"; }<br><br>
defined - is the value 'something' or the unique value
undef<br>
if ( ! defined
$systolic_reading ) { warn "dial 911"; }<br><br>
length - is the value 'empty'?<br>
if ( length $speech ) { print
"They said '$speech'\n"; }<br><br>
'truth' - various shades of yes, a couple
ways to say no<br>
if ( $answer ) { print
"Some kinda yes ('$answer'); }<br>
else
{ print "Some kinda no ('$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. Once you've looked these up in perlfunc (especially
see the discussion of exists) and the discussion "Scalar
values" 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>