APM: Next dumb Q: IF NULL????

Thomas L. Shinnick tshinnic at io.com
Tue Oct 17 20:29:16 PDT 2006


At 04:51 PM 10/17/2006, CaptNemo wrote:
>Why is it so hard to check for null values in perl!?!?!

I confess to wanting the smallest set of things to remember:

   exists            - test whether array or hash element is 'present'
         if ( exists $lotto{23_31_07_42_18_05} ) { die "rich"; }

   defined  - is the value 'something' or the unique value undef
         if ( ! defined $systolic_reading ) { warn "dial 911"; }

   length    - is the value 'empty'?
         if ( length $speech ) { print "They said '$speech'\n"; }

   'truth'     - various shades of yes, a couple ways to say no
         if ( $answer ) { print "Some kinda yes ('$answer'); }
         else               { print "Some kinda no  ('$answer'); }

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)

>Two situations:
>1) checking is a variable is empty:
[snip]
>2) checking to see if command line args were present:
[snip]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/austin/attachments/20061017/01af1b38/attachment.html 


More information about the Austin mailing list