$index = int(rand($symbol_size));
... inside the while loop (right at the top of the loop), and then remove the occurrence at the end of the loop?
That is, not:
foo();
while (1) {
bar();
foo();
}
But instead:
while (1) {
foo();
bar();
}
It should have the same effect; be more compact and avoid repetition.
Anyway, I believe the reason you're leaking memory is that your evaluated strings can end up containing variables, and those variables are not lexicals, so they get stored in the package stash.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
|