in reply to Proper way to thread this in PERL.
I'm no threads expert but one thing I see problematic in your code is that you use sleep as a crude delimiter of threads in the hope that 5 threads per 5 seconds is not too much. Much better would be to check for number of threads with scalar(threads->list()) and sleep as long as this number is at maximum. Only when that number goes down another thread should be generated
Something like this:
while (threads->list()<$threadsmax) { sleep(1); # or threads->yield; but I'm not sure what happens if you +call this in the main thread } print ".";
I added the print for debugging purposes. If you see that no new "." get printed after a while it would mean no threads finish.
In Section
Seekers of Perl Wisdom