occasionally some of the results are just plain wrong.
Actually this is your problem No. 1. If the results are sometimes wrong, you can never trust the output. Which means that it doesn't matter how long it takes to get wrong results.
Note, I am using the recommendations from Perl Best Practices.
Surely not all of them. For example you declare way too many variables up front. And you're using many variables with similar names that really belong into a compound data structure (array or hash).
Here's my proposal on how to proceed:
- Separate the calculation from any HTML input and CGI output
- Write tests for the actual calculations. See Test::Tutorial for a short, gentle introduction
- Fix any errors in the calculation
- Once you're convinced of the correctness of the calculations, work on the speed. Also feel free to show us the working code and the test suite. I have a few ideas of what might speed up your code, but I wouldn't dare to change anything without a proper test suite.
One of your structural problems with both popnum1 and popnum2 is that it creates a full 2-dimensional array, and then returns a single element. I guess an effort can be made to short-circuit the calculation with knowledge of $x and $y.
There might also be a statistical model that can analytically predict some of the results, and thus avoid a whole lot of calculations, but so far I don't have the time to dig deeper into this.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.