undef

All scalars that have not been explicitly defined have the value of undef. You can also assign this value to a scalar. In this way, undef is pretty much like NULL...

my $a;
my $b=undef;

The thing is, you can't explicitly check for undef, so no

if ($b==undef) {...} # no

So, instead you need to

if (defined($b)) {...} # yes

I suppose that would be is_not_null or whatever. This is handy for setting and checking parameters to a function that aren't always needed.

Posted 23 Aug 2007, tagged with perl