From: John Porter [mailto:[EMAIL PROTECTED]]
> 
> Randal L. Schwartz wrote:
> > 
> > Yes, I'd be in favor of making return() in a valued block 
> > (as opposed to a looping block) abort the block early and
> > return the value.  


> Imho, it should return the value, but not abort the block.

I.e. stick with the current behaviour. -Yes, I'd be surprised if 

sub mygrep (&@) {
  my ($coderef, @list, @stack) = @_;
  &$coderef and push(@stack, $_)  foreach (@list);
  return @stack;
}

@a = mygrep { return ($_ <= 2) ? 1 : 0 } (1, 2, 3, 2, 1);
print "\@a = @a\n";

Resulted in: @a = 
Instead of the current Perl 5:  @a = 1 2 2 1

> After all, grep is (ostensibly) prototyped as grep(&@), so I
> expect to pass it a sub block.  And that block gets called
> once per iteration over the input list; "return" is what I
> expect it to do once per iteration, implicitly; so using
> C<return> explicitly to mean "no further iterations" is highly 
> counterintuitive, or at least inconsistent.

Reply via email to