in reply to Improve my coding

The output of your program is hard to read. Consider using the Perl Format mechanism. See perldoc perlform
jbt

Replies are listed 'Best First'.
Re^2: Improve my coding
by Anonymous Monk on Jun 14, 2009 at 21:03 UTC
    maybe you could consider putting the radii and the cross sections in the same array as they seem to belong together.
    #!/usr/bin/perl -w
    
    # loop over drop radius from 1 micron to 100 microns in steps of 2 microns
    # use each radius ($r) to compute cross section
    # if r < 20 microns,  use (pi)*(r^2)*a*(1-exp(-c*r))
    # if r >= 20 microns, use 2*pi*(r^2)
    use strict;
    use Data::Dumper;
    
    my @cross_sections = ();
    my ($pi, $a, $c) = (atan2(0, -1), 1.18, 0.28e6);
    
    for (my $i = 1 ; $i < 100; $i += 2) {
        my $r = $i / 1000000;
        if ($i < 20) {
            push @cross_sections, [$r, $pi * $r**2 * $a * (1 - exp(-$c * $r))];
        } else {
            push @cross_sections,[$r, 2 * $pi * $r**2];
        }
    }
    
    print Dumper(\@cross_sections);