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:

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
Nothing too bad and all of these critics can be easily mended.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.