note
jdporter
<p>
The same thing [tobyink] and [tye] said, though more obtusely and snarkily.
</p>
<p>
Here's another example:
</p>
<c>
tie my $var, 'Some::BlackBox::Module';
$var = "45";
if ( $var ) { print "var is true\n" } # doesn't print! WTF?
</c>
<p>
The mere fact that an expression evaluates to a true value in scalar context doesn't mean it <b>is</b> true.
</p><p>
[doc://tie] and [doc://overload] are among the user-accessible features which can muddy the true/false waters.
</p><p>
An example like this should make the principle more obvious:
</p>
<c>
my $obj = ObjectWithLotsOfOpaqueStructure::AndLotsOfHiddenState->new(
-use_overloading => 1,
);
if ( $obj ) {
print "obj is 'true'.\n";
# What does this even mean?
# Maybe obj is an iterator with another available item?
}
</c>
862
999632