Aug 31, 2012, 7:57 AM
While you work on overhauling the code, you may want to take these things into consideration.
Re: [Sam Kennedy] Thread or Fork?
1) You're calling your main() sub prior to declaring/initializing the file scoped vars that the sub uses and you have way too many of those vars.
2) The use of a main() sub is unneeded and only servers to add unnecessary indentation.
3) Every sub is accessing file scoped vars directly, which is a bad coding practice. You should a) declare your vars in the smallest scope that they require and b) pass globally scoped vars to subs rather than accessing them directly.
4) You have way too much duplication of code. Instead of having individual subs that update a specific var, you should make the subs more generic and pass in vars by reference. That alone would mean you could drop most of those subs.
5) The C style for loop is very verbose and looks cluttered. It's much cleaner and easier to use Perl's style of the for loop.
6) I suspect that the multiple use of nested for loops could be the source of part of the slowdown. I have not analyzed them enough, but I'm pretty sure that those blocks can be reworked to reduce the amount of looping.
7) Your save_genes() sub looks pretty inefficient. The use of the join function could help in cleaning up or getting rid of those for loops. It might be better and more efficient to build up a data structure and then dump that to the file in one print statement.
With more analysis, I could probably come up with more things to consider, but that should be enough to get started.
(This post was edited by FishMonger on Aug 31, 2012, 7:58 AM)