in reply to Baby Steps "if" behavior?
If I remember correctly 0, null string, and empty string are all false answers. However,
0 and empty string are defined answers. $kaka ne "" checks to see if $kaka
is equal to the empty string. Whereas defined $kaka checks
to see if $kaka is something other than 0, null, or empty. I also think there
are some differences for defined and exists. I think exists
only applies to hash values. I know this isn't a complete answer
but it gets you pointed in the right direction, I hope. Check in perlfunc for
more complete answers.
Update:
Oops. You can uses exists to check on array elements. Next time I'll
read perlfunc before shooting off with the fingers.
RE: RE: Baby Steps
by sean (Beadle) on Jun 23, 2000 at 04:04 UTC
|
Well... defined $kaka actually checks to see if $kaka is defined at ALL. something that is defined as zero, null, or empty is still defined.
sean@anticharm:~$ perl -e 'print "defined!\n" if defined $foo'
sean@anticharm:~$ perl -we '$foo = 0; print "defined!\n" if defined $f
+oo'
defined!
sean@anticharm:~$ perl -we '$foo = ""; print "defined!\n" if defined $
+foo'
defined!
As far as I am aware, once you define something you must use undef (or assign it the value of something undefined: undef $baz; $foo=$baz;) if you want it to be undefined again. | [reply] [d/l] |
RE:(2) Baby Steps (exists on array)
by Russ (Deacon) on Jun 23, 2000 at 03:15 UTC
|
Using exists on an array is a new feature in 5.6
For those of us too lazy (busy) to upgrade, you were right.
:-)
Russ | [reply] |
|