in reply to Bizarre Results when Creating a Closure
It binds to the variable $i, not the current value. And since you change the variable later, the value changes too.my $psub = sub { $chosen_idx = $i }
If you want to bind it to the current value, you have to copy it, as you did in your $icopy example.
|
|---|