my $r = ($i)*(1e-6); #radii are in microns
I would keep the value of the radii as an integer as long as possible and only "scale" it in the actual calculation. Integers will be presented without any loss of precision in Perl, but once they are turned into a real, it is not certain that they are still exact as their internal representation may involve a repeating sequence of bits, which may be a little bit more or less than you expect and tests such as if ($r<2e-5) may give unexpected results in edge-cases. In this case, it seems to be OK.
An interesting discussion on this issue can be found in My floating point comparison does not work. Why ?.
Running your code through Perl::Critc gives the following:
Nothing too bad and all of these critics can be easily mended.Code before strictures are enabled at line 1, column 1. See page 429 +of PBP. Severity: 5 Code before warnings are enabled at line 1, column 1. See page 431 of + PBP. Severity: 4 Use "<>" or "" or a prompting module instead of "" at line 1, column 9 +. See pages 216,220,221 of PBP. Severity: 4 Always unpack @_ first at line 29, column 1. See page 178 of PBP. Se +verity: 4 Magic variable "$a" should be assigned as "local" at line 35, column 4 +. See pages 81,82 of PBP. Severity: 4 Always unpack @_ first at line 46, column 1. See page 178 of PBP. Se +verity: 4
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In reply to Re: Improve my Code: Subroutines
by CountZero
in thread Improve my Code: Subroutines
by cheech
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |