[oak perl] The mysterious "undef"
Kester Allen
kester at gmail.com
Fri Mar 18 09:22:49 PST 2005
Hi Sandy--
Here's a quickie example of a way to detect undef-- test for it with
"defined", and then print something based on the result of that:
$x = undef;
print "x is undef\n" if not defined $x;
$y = 0;
print "y is defined\n" if defined $y"
One place I run into undef frequently is in subroutines optional
arguments. I.e. if you called a sub like:
sub test {
my ( $x, $y, $z ) = @_;
}
with "test( 1, 2)", $x would be 1, $y would be 2, and $z would be
undef (not zero).
perldoc -f defined has some good text on this.
--Kester
On Fri, 18 Mar 2005 11:10:22 -0500, Sandy Santra <santranyc at yahoo.com> wrote:
> I keep seeing "undef" mentioned in the llama book.
>
> I've tried to define a variable as not having a value, theoretically being
> "undef," but when I use the print command, I never see "undef" print to my
> screen; nothing prints at all.
>
> I wanted to learn the different between a zero value and undef because the
> llama book keeps saying there is one. Is this a pointless issue to pursue?
>
> Clarification greatly appreciated. Thanks.
>
> _______________________________________________
> Oakland mailing list
> Oakland at pm.org
> http://mail.pm.org/mailman/listinfo/oakland
>
More information about the Oakland
mailing list