spx2 has asked for the wisdom of the Perl Monks concerning the following question:

How does Perl distinguish between this two situations:
 print ($a||$b) where it should print either $a or $b
 print ($a||$b) or 0 in case that is evaluated in list context.

Replies are listed 'Best First'.
Re: in search of disambiguation
by Fletch (Bishop) on Feb 15, 2008 at 13:39 UTC

    There's not two situations. The expression $a || $b evaluates to either $a's value if it has a not-false value (for the normal plethora of false values), othewise $b's value is used. What may happen in some cases is that expression's value is then used in a boolean context where it's further evaluated as true/false (e.g. if( $a || $b ) { ... }), but that's not really relevant in your example since print isn't going to impose a boolean context.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.