2 ms·
It's a -sort of- bug. perl 5.10 actually throws a warning when you trip it, and provides a 'state $x' keyword that provides the same functionality as 'my $x if
by mst 18y ago
It's a -sort of- bug.
perl 5.10 actually throws a warning when you trip it, and provides a 'state $x' keyword that provides the same functionality as 'my $x if 0' safely.
The basic problem is that the 'my' causes a lexical pad entry to be generated at compile time, but because the if 0 prevents the statement running at runtime it doesn't get reinitialised on your way round the loop.
(I've also made this comment on your blog, but it's the sort of thing people should manage to find easily so I figured it'd be ok to duplicate it)
- dangoldin 18y agoYea no worries, the more people that learn this the better - it took me a bit to diagnose. That was basically my understanding. It looks like the scope of the my gets a bit weird with that if(0) there.