|XP is just a number|
Re: Duplicate Results from Subroutineby stephen (Priest)
|on May 23, 2013 at 21:08 UTC||Need Help??|
To fix this specific problem, you need to localize @cands in abv() rather than up at the top of the script.
Each time you call abv(), it remembers @cands from the last time you call it, and returns the duplicate values as well as the new ones.
It's a good idea to localize your variables to the smallest possible block. Declare them in the subroutine that's using them.
You're also assuming that $numlist_avg has already been determined. If you tried calling abv() before setting $numlist_avg, you might wind up with a hard-to-trace error.
While we're at it, you're passing @numlist to the subroutine as an argument, but not actually using that argument. If you called abv(1,2,3) it would still go over @numlist to get the result. So, instead, you should do: