Damian Conway wrote:
>
> 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.
Right. Well, perl6 doesn't exist yet. See my other recent post for
a proposal on rectifying the semantics of sub return in the presence
of last.
To continue: last-ing/next-ing out of a sub allows the Last Evaluated
Value (as per current perl semantics) to be returned, and a special
flag is also returned to the caller indicating that last/next was used.
Functions such as foreach will discard the returned value, regardless,
but care about the next/last/redo flag; functions like grep mainly
care about the return value, but honor the "last" if present.
heh. for a normal sub,
sub foo {
return( 42 );
}
finds OMWTDI as
sub foo {
42;
last;
}
Somehow, this seems like very natural perl to me.
--
John Porter
We're building the house of the future together.