in reply to Passing an array to a subroutine help?!
if ($val != "0")
You are using a numerical comparison on a text value which means that Perl has to convert the text values to numbers. Normally Perl will make the correct conversion but this may cause problems.
@values=(@values,$val);
That is usually written as:
push @values, $val;
&maximum(@values,$arraysize); ... sub average { @stuff = @_; my $sum = 0; ($sum+=$_) for @stuff; my $average = $sum / $arraysize; return $average; }
It looks like you meant average instead of maximum here? You are passing $arraysize as well as @values to this subroutine which means that @_ inside the subroutine will have one more value than the numbers you want to calculate the average for. You could simply remove that value using pop but there is no reason to pass the value in the first place as @_ would then have the same number of elements as @values and using @_ in scalar context would result in the same value as using @values in scalar context.
|
|---|