http://qs1969.pair.com?node_id=999756


in reply to Re^4: What is true and false in Perl?
in thread What is true and false in Perl?

The same thing tobyink and tye said, though more obtusely and snarkily.

Here's another example:

tie my $var, 'Some::BlackBox::Module'; $var = "45"; if ( $var ) { print "var is true\n" } # doesn't print! WTF?

The mere fact that an expression evaluates to a true value in scalar context doesn't mean it is true.

tie and overload are among the user-accessible features which can muddy the true/false waters.

An example like this should make the principle more obvious:

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? }