Randal Schwartz wrote:
>We really need a clean way to distinguish those four cases:
>
> "yes" and keep going
> "no" and keep going
> "yes" and abort after this one
> "no" and abort after this one
>
>What would you have "last" do? And how would you distinguish "the
>other one"?
Sounds like people are trying to fit two booleans into one expression.
Probably what is needed is for grep to have two control expressions:
one to determine whether each element is selected to be put into the
output list (grep's current boolean expression), and one to determine
whether grep should continue execution.
Perhaps a new "pass" keyword should be added, which passes the
current list element through the filter.
@L = (1, 2, 3, 10, 3, 2, 1);
@l = grep {pass if $_>1; last if $_>9} @L; #--> (2, 3, 10)
@l = grep {last if $_>9; pass if $_>1} @L; #--> (2, 3)
@l = grep {pass if $_>1; next if $_>9} @L; #--> (2, 3, 10, 3, 2)
@l = grep {next if $_>9; pass if $_>1} @L; #--> (2, 3, 3, 2)
A grep block with no explicit 'pass' would pass if the last expression
in the block evaluates to true, just as grep does now:
@l = grep {$_>9} @L; # same as:
@l = grep {pass if $_>9}; #--> (10)
----------------------------------------------------------------------
Eric J. Roode, [EMAIL PROTECTED] print scalar reverse sort
Senior Software Engineer 'tona ', 'reh', 'ekca', 'lre',
Myxa Corporation '.r', 'h ', 'uj', 'p ', 'ts';