in reply to defined vs null string
Here is a classic case of why you should use strict; and use warnings; when you are writing Perl.
The first thing that jumps out at me is that Perl is not like C, a compiled language. Perl is an interpreted language and the use of my $y; is to establish the context of the variable not "define it" in the classical sense of the term. As long as you do not assign a value to $y it will have the psuedo-value of undef and hence the evaluation of the function defined($y) is going to return truefalse.
Just for tee-hees and ha-has I took your code and started playing around with it. First thing I did was add use strict; followed by use warnings;. All was happy util the if ($y eq "") conditional whereupon the warning Use of uninitialized value in string eq at test.pl line 14 was issued.
OK... so let's initialize the variable.
Now the output becomes:my $y = "";
Y is defined Y is null string
Hope this helps.
|
|---|