in reply to Re: How to make references more like aliases?
in thread How to make references more like aliases?

ihb,
I had thought of a tied solution myself, but it doesn't really fall into the user-friendly category. You have to tie it each time you want to have a different number of elements per loop. As far as the splice problem - I originally copied the array, which is what lead to this post. I mostly handled it since each iteration I check to see if I am falling over the edge - the one case where it could still bite me is if the starting position is already in the abyss. That is easily solved with :
return () if $done || $pos > $#$list;

Cheers - L~R

Replies are listed 'Best First'.
Re^3: How to make references more like aliases?
by ihb (Deacon) on Sep 28, 2004 at 14:53 UTC

    it doesn't really fall into the user-friendly category

    By adding a simple wrapper subroutine it gets just as user-friendly as the other functions in this thread. See update.

    As far as the splice problem / ... / I mostly handled it since each iteration I check to see if I am falling over the edge

    There are other problems as well. You need to consider whether or not you want unshifts to effect your iterator (after you've done a couple of iterations); compare with foreach's behaviour. What's best here may very well depend on the situation. One solution is to just document that you may not do any size-changing modifications of the original array while using the iterator.

    ihb

    Read argumentation in its context!