To use a hash as all other monks have suggested surely makes your code much more beautiful and structured.
If I speak strictly to the speed problem, the major issue is that you are repeating the [] operation unneccessarily, when you only need it twice. String operation is very expensive.
You should be able to speed your code up, simply by doing this right before your if-else chain:
my $a = $genome[$i]; my $b = $genome[$i + 1];
And in the subsequent code, only use $a and $b, not [] operation any more.
This is a direct answer to your speed issue. Don't get me wrong, you still should use hash as your storage, as it not only makes your code more structured, as a matter fact, but also removes the unnecessary usage of [] operation.
In reply to Re: how can I speed up this perl??
by pg
in thread how can I speed up this perl??
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |