Your code is very difficult to grasp for the following reasons. It is also failing for at least one of the following reasons:
Pass all variables and values into your subs through @_, not through global osmosis. Define your subs outside of the loop. Your final use of 'last' seems to be useless.
I may be missing the mark on scope closing around the subs after the first iteration of the loop, but if I'm right about that, there's your biggest problem. One of the very few legitimate reasons to use a variable from a broader scope within a sub is to set up an intentional closure. I don't think you're intentionally doing that. Instead, it's an unintentional consequence of the way you've got your code structured.
Dave
In reply to Re: exiting a for loop
by davido
in thread exiting a for loop
by velocitymodel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |