Cybercosis has asked for the wisdom of the Perl Monks concerning the following question:
I won't get into the train of thought that led to the following thought experiment:
$foo = "NARGLE"; print ref($foo), "\n"; defined(ref($foo)) ? print "Y\n" : print "N\n"; ref($foo) == undef() ? print "Y\n" : print "N\n";
The print ref() obviously prints nothing but a newline. However, I was quite surprised when the two trinary statements both printed "Y". I went back to the documentation and looked up both defined() and undef(). Defined "Returns a boolean value telling whether EXPR has a value other than the undefined value 'undef'...". Looking over at the undef docs, it "always returns the undefined value". How is it possible for ref($foo) to be both defined and == undef?
~Cybercosis
nemo accipere quod non merere
Back to
Seekers of Perl Wisdom