John wrote:
> > I don't know how grep works internally. I don't know if grep pushes
> > elements into @a one at a time, or if it returns a finished list of
> > elements which pass the conditional block. If it is the latter as I
> > assume, a short-circuited grep would return a list of all the
> > elements of @b that had passed through to that point.
>
> Actually, that's what it would do regardless of the internal
> implementation. Either way, the result (assigned to @a) is the
> list of items which passed the condition, up to the point the
> loop was terminated via "last".
This is correct, but the phrase "...up to the point..." is ambiguous.
See below.
> > > So: should
> > >
> > > scalar grep { 1 and last } LIST
> > >
> > > return 1, if LIST is not empty,
>
> Yes. The first item in LIST passed the condition,
> and then the loop terminated.
My understanding would be that that is not so.
The expression C<1 and last> does *not* evaluate to true -- it does not
evaluate to *anything*. So the C<grep> is terminated by the C<last>
without the block having ever evaluated true. So no element of LIST is
ever "passed through". So the C<scalar grep> evaluates to zero.
Damian