Suppose I want to say: sub sublist(@a, $start, $cnt) { return @a[$start] +next --$cnt; }
where +next is a binary macro that takes as its lhs an array element access, and its rhs a number, and returns a list of the array element followed by the next RHS elements. It seems obvious to me that +next has to be a macro, since it has to detect this weird condition of "accessing an array element". How do I code that? More generally, is there any way (via trait or property or whatever) to recognize when something as basic as $_ is an array element, and get the containing array(s) and somehow do the right thing? (I can't count the number of times I've been frustrated by map/grep because there's no way to get at the "next" or "prior" element in the sequence.) =Austin