Instead of hard coding $pi twice, I'd put near the top of the file:
my $PI = 2 * atan2(1, 0);
I use capitals to indicate the variable plays the role of a constant - it shouldn't be assigned to. Some people will suggest using use constant PI => 2 * atan2(1, 0), but that style gives constants that are harder to interpolate, so I tend to shy away from them.

I also note that both subroutines are almost the same. I would use just one subroutine, and an extra parameter. Something like:

my $PI = 2 * atan2(1, 0); my $A = 1.18; my $C = 0.28e6; my $HWM = 2e-5; my $SCALE = 1e-6; sub sigma; my (@rads, @sigs); for (my $i = 1; $i <= 100; $i += 2)) { my $r = $i * 1e-6; push @rads, $r; push @sigs, sigma($r, $r >= $HWM) } print "radii: @rads\n"; print "sigmas: @sigs\n"; sub sigma { my ($rad, $high) = @_; $PI * $rad ** 2 * ($high ? 2 : $A * (1 - exp(-$C * $rad))); }
I didn't run or even compiled the code above, so it may be full of typos.

In reply to Re: Improve my Code: Subroutines by JavaFan
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.