use strict; use warnings; my ($i); #declare global $i for for loop my (@sigmas, @rads); #declare arrays for storage of radii and sigma results for ($i=1;$i<=100;$i+=2) { # 1, 3, 5, ..., 99 my $r = ($i)*(1e-6); #radii are in microns push (@rads, $r); #store the correct radii in array for print at end if ($r<2e-5) { #if the radius is <20microns, send to sub sigmalow my $sig = sigmalow($r); #store the return in $sig push (@sigmas, $sig); #add result to the final sigma array } else { #if the radius is >=20microns, send to sub sigmahigh my $sig = sigmahigh($r); #store the return in $sig push (@sigmas, $sig); #add result to the final sigma array } } print "radii: @rads \n"; print "sigmas: @sigmas \n"; exit; sub sigmalow { #to compute sigma when radius < 20microns my ($pi, $a, $c, $rad, $sig); my (@r); $pi = 3.14159; #constants $a = 1.18; $c = .28e6; @r = @_; #transfer the argument to @r $rad = $r[0]; #is this step necessary? $sig = $pi*($rad**2)*$a*(1-exp(-$c*$rad)); #calculation of sigma return ($sig); #send back the result } sub sigmahigh { #to compute sigma when radius >= 20microns my ($pi, $rad, $sig); my (@r); $pi = 3.14159; #constant @r = @_; #transfer the argument $rad = $r[0]; #necessary? $sig = 2*$pi*($rad**2); #compute return ($sig); #return it }