You might think of it as a quirk but it doesn't look like a bug to me.
In the first instance the anonymous subs are closing over the local $i which is reset every time through the loop - ie. it is a different variable on each iteration. That is how the different values persist. In the second instance, there is no local $i, just the outer global one and so the sub closes over that and clearly its value changes over time but all three subs are now essentially the same.
🦛
In reply to Re: Closures and scope of lexicals
by hippo
in thread Closures and scope of lexicals
by haj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |