This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

|| should propagate result context to both sides.

=head1 VERSION

     Maintainer: Peter Scott <[EMAIL PROTECTED]>
     Date: 5 Aug 2000
     Version: 1
     Mailing List: [EMAIL PROTECTED]
     Number: 45

=head1 ABSTRACT

Currently the expression

     lvalue = expr_A || expr_B

evaluates C<expr_A> in scalar context, regardless of the type of C<lvalue>, 
only propagating list or scalar context to C<expr_B>.  This proposal is 
that the context of C<lvalue> should be propagated to C<expr_A> as well.

=head1 DESCRIPTION

It would be nice to be able to say

     @a = @b || @c

instead of having to resort to

     @a = @b ? @b : @c

The reason that it is not currently possible is that C<@b> (or the list 
expression in its place) has to be evaluated in scalar context to determine 
whether to evaluate C<@c>, and that propagating context to C<@b> would 
require reevaluating it, which might have undesirable side effects (instead 
of C<@b>, it might be C<decrement_balance()>).

=head1 IMPLEMENTATION

It seems that it ought to be possible to evaluate something in a list 
context and test whether there are any entries in the resulting list 
without having to reevaluate the expression in a scalar context.  The 
work-around with the trinary operator also evaluates C<@b> twice.

There is obviously no need to modify the behavior of the C<&&> operator.

=head1 REFERENCES

L<perlop/"C-style Logical Or">

Reply via email to