Damian Conway wrote:
> A C<grep> such as:
>
> @array = grep BLOCK LIST
>
> is equivalent to:
>
> @tmp = ();
> foreach (LIST) { push @tmp, $_ if do BLOCK }
> @array = @tmp;
>
> That similarity would not change in any way under the proposal
> (except to be made stronger!)
it could be made weaker, so that "last" within the grep block
expands to
do {push @tmp, $_; last}
> If BLOCK contained a C<last>, the invocation of that C<last> would
> *immediately* cause the implicit C<foreach> to terminate,
> *without* pushing any value onto @tmp from the final execution of
> the code in BLOCK.
That's not DWIM
> That is not an onerous constraint on inequalities: < vs <= gives you
> the control you need. But it makes "short-circuit as soon as C<grep>
> lets through a specific value" ugly:
>
> my $seen;
> $has_odd_elem = grep { $seen && last; $_%2 && ++$seen } @numbers;
Exactly the sort of chicanery grep/last is meant to avoid. So the question
becomes, how do we crowbar "last" in without altering the returned value in
C<map> blocks. I'm for putting it after a comma. Which matches the syntax of
John Porter's proposal about internally converting the block to a subroutine.
--
David Nicol 816.235.1187 [EMAIL PROTECTED]
perl -e'map{sleep print$w[rand@w]}@w=<>' /usr/dict/words