Change average() to use its parameters, not the top-level @array directly; then you can limit @array to the appropriate context:
sub average { if (@_) { my @temp = @_; my $sum = 0; foreach (@temp) { $sum = $sum + $_; } return $sum/@temp; } }
edit: fixed indenting for readability
In reply to Re: resetting a foreach loop!
by pryrt
in thread resetting a foreach loop!
by lunette
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |