Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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!

In reply to Improve my coding by cheech

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found