On Mon, Jul 11, 2005 at 05:33:26PM -0400, David Golden wrote:
> http://rt.cpan.org/NoAuth/Bug.html?id=11304
> 
> My suggestion turns on the question of whether it's possible to 
> differentiate the context between a true boolean context ( "foo() if $p 
> || $q" ) and a "pseudo-boolean" context that is really part of an 
> assignment ( "my $foo = $p || $q" ) or just a standalone statement ( "$p 
> || print $q" ). 

"my $foo = $p || $q" is not boolean.  I'm not even sure you can call it
"pseudo-boolean" without understanding the surrounding code.  How do you
know that $q can never be false?

The other examples in the ticket play out the same way:

        bless {}, ref $class || $class;

$class being false would be quite the error.  Devel::Cover can't know that
in most cases you want to ignore the 0 || 0 case because you assume $class
to always be some true value and don't think its worth testing that it
might be false.


> Want.pm seems to imply that this might be possible, but I don't know the 
> guts of Perl well enough.  The concept I had was that *EXCEPT* in true 
> boolean context, the "$p || $q" idiom is (I think) pretty much logically 
> equivalent to a trinary operation "$p ? $p : $q" (ignoring potential 
> side effects) and thus the truth table in this situation only needs to 
> include the first operand, thus avoiding the false-alarm.

That assumption only works in void context.

        # Don't care about the return value of die.
        open FILE, $foo || die $!;

        # DO care about what $q is
        foo( $p || $q );

And the special ||= case:

        $p ||= $q;


-- 
Michael G Schwern     [EMAIL PROTECTED]     http://www.pobox.com/~schwern
Reality is that which, when you stop believing in it, doesn't go away.
        -- Phillip K. Dick

Reply via email to