Along those lines. I don't like the idea of it leaking across scopes. The version I have is a little different. It actually stringifies the reference and caller info to avoid collisions. Using only the ref causes side effects at a distance.
my @array = (1..12);
while(my @els = elements @array, 3 ){
last if grep { $_ eq 2 } @els;
}
my @five = elements @array 5; # Would get (4,5,6,7,8)!DWIM
Using both fixes this problem but can still suffer if the iterative construct is exited prematurely.
{
while (my @els = elements @giantarray, 10 ){
# Do stuff
last if $els[0] == $somecondition;
}
redo if $someothercondition;
}
The later probably almost never occur in most code, but when it does, I'm sure it would take much head scratching before deciding where the problem lies.
-Lee
"To be civilized is to deny one's nature." |