Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> writes: >I'm trying to write an XS module that will allow people to move forward >(or backward) within a for(each) loop. The canonical example would be: > > my @data = (1 .. 10) { > > for (@data) { > my $next = For::next_iter(); > print "$_, $next\n"; > } > >And the output would be > > 1, 2 > 3, 4 > 5, 6 > 7, 8 > 9, 10
That sounds hard in general. We optimize itterators these days. > >I've tried writing code that modifies PL_markstack_ptr, but I'm afraid my >changes aren't effecting the code at all. the 'for' OP will have already popped its MARK (assuming it really got data on stack) and may even have index into AV in a C variable which was in a register, which you can't see 'cos SPARC (say) uses register windows. >Does anyone know how to go >about doing this? I'm under the impression I need to access a "saved" >version of PL_markstack_ptr (that's been pushed onto the stack) and work >on it there, but I don't know how to do that. I think it is too late for that...