in reply to resetting a foreach loop!
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: resetting a foreach loop!
by ikegami (Patriarch) on Nov 17, 2017 at 19:16 UTC | |
by pryrt (Abbot) on Nov 17, 2017 at 19:36 UTC | |
by ikegami (Patriarch) on Nov 17, 2017 at 20:00 UTC | |
by AnomalousMonk (Archbishop) on Nov 17, 2017 at 20:15 UTC | |
by ikegami (Patriarch) on Nov 18, 2017 at 00:07 UTC | |
| |
|
Re^2: resetting a foreach loop!
by lunette (Acolyte) on Nov 16, 2017 at 22:24 UTC | |
by brostad (Monk) on Nov 17, 2017 at 11:27 UTC |