I'm training myself in Perl and have been coding some basic programs that my professor gave me. The one below works just fine, but I thought I'd gain some insight to more efficient coding if I posted it for the community to critique. Any and all suggestions or comments are greatly appreciated!
#3_3.pl
#loop over drop radius from 1 micron to 100 microns in steps of 2 micr
+ons
#use each radius to compute cross section
#if radius <20 microns, use (pi)*(r^2)*a*(1-exp(-c*r))
#if radius >= 20 microns, use 2*pi*(r^2)
#VARIABLE DECLARATION
#--------------------
my ($r, $rad, $twopi, $sig, $pi, $a0, $c0);
my (@radii, @rads, @sigs);
#--------------------
use strict;
@radii = (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 3
+3, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67
+, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99);
@rads = ();
@sigs = ();
$pi = 3.14159;
$twopi = (2)*(3.14159);
$a0 = 1.18;
$c0 = (0.28e6);
foreach $r (@radii)
{
$rad = (1e-6)*$r;
push (@rads, $rad);
if ($r>20)
{
$sig = $twopi*($rad**2);
push (@sigs, $sig);
}
else
{
$sig = $pi*($rad**2)*$a0*(1-exp((-$c0)*$rad));
push (@sigs, $sig);
}
}
print "@rads \n";
print "@sigs \n";
Thanks!
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.