in reply to Boolean array indexing

A trivial change you might like is:

@a= map{$a[$_]} grep {$b[$_]>1 } 0..$#b;

which doesn't reduce the complexity, it's exactly the same code, but does eliminate one manifest array. At the end of the day you pretty much can't reduce the complexity. You have to select elements based on your criteria and you have to map those elements to your other array.

If you are free to alter your data structures you could instead:

my @data = ([6, 3], [7, 2], [8, 1]); my @result = grep {$_->[1] > 1} @data;

which is much better if the data are paired. It may even be worth the effort to generate an array of paired data to gain the benefit of uniform handling in that way:

my @dataA = (6, 7, 8); my @dataB = (3, 2, 1); my @data = map {[$dataA[$_], $dataB[$_]]} 0 .. $#dataA;
True laziness is hard work