in reply to Re^2: Prob with 'while' loop and subroutine calling
in thread Prob with 'while' loop and subroutine calling
The while loop decrements $incEnergy from $maxEnergy downward in steps of $scale (which is negative) until $incEnergy is less than $minEnergy. It looks fine to me, although it may be a good place for a C type for loop:
for ($incEnergy = $maxEnergy; $incEnergy > $minEnergy; $incEnergy += $ +scale)
and omit the $incEnergy = $incEnergy+$scale; at the end of the loop. It looks like the while loop is generating points along an energy axis.
if(@$x1) { should be if(@$x) {. The test checks to see if @$x contains any elements.
The LoadFile sub takes a number of reference parameters. The first line in the sub:
my ($filename, $x, $y, $min, $max) = @_;
declares the variables and sets them to the parameter values. The last four variables are references. So $$max is the scalar variable that $max refers to. $x and $y are references to arrays and $y->[-1] is the last element of the array refered to by $y. So the line:
$$max = $y->[-1] if $y->[-1] > $$max;
means assign the last element of @$Y (the array that $Y refers to) to the scalar that $max refers to if the element is greater than the current maximum. (Note there was an error in this code. See update in previous post.)
|
|---|