We don't bite newbies here... much | |
PerlMonks |
Re: Closure confusion in Tkx (declarations in loops)by LanX (Saint) |
on Jul 13, 2019 at 12:50 UTC ( [id://11102790]=note: print w/replies, xml ) | Need Help?? |
Hi I'm not an expert on Tkx, but I think you might get bitten by the way closure variables are "shared". Please compare
actually your case with a c-style loop is how it's supposed to be, your my $x has only one instance and only gets a new value with each iteration.²
To avoid such confusions it's always safe to call a "generator" sub which returns a closure.
Cheers Rolf
footnotes
°) ²) a c-style for is semantically just a while-loop with a prior declaration.
updatesexpanded example with clearer output and generator case
In Section
Seekers of Perl Wisdom
|
|