Jarkko Hietaniemi wrote:
>
> How about using 'return', then? That could, ahem, return both true and
> false values.
Hmm. I think it boils down to the fact that we'd like a grep block
to have characteristics of both a subroutine and a true loop block.
Here's a proposal which would mostly eliminate the dichotomy:
allow next/last/redo to pertain to a subroutine. I.e. last would
exit the sub, and redo would be essentially equivalent to goto &self;
The last-ness/next-ness of the sub return would be communicated to the
caller, in case it's interested (as grep would be).
Then grep blocks would simply be defined to be real subs.
grep { return /pat/ } @foo
would be the same as
grep { /pat/ } @foo
If one were looking for the first matching item, last would work:
grep { /pat/ and last } @foo
# return()s the value of $_=~/pat/, which will be true
If the value of the test is wrong (and "not" won't do), the
return value can be set before the last:
grep { crud($_) and 0, last } @foo
# reject the item even though crud() returns true.
grep { crud($_) or 1, last } @foo
# accept the item even though crud() returns false.
--
John Porter
We're building the house of the future together.