Think about Loose Coupling  
PerlMonks 
Re: I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated.by Loops (Curate) 
on Nov 20, 2014 at 02:37 UTC ( #1107854=note: print w/replies, xml )  Need Help?? 
So as you consider each number now, you're adding it to $total so that it is part of the final average. Similarly you need to keep the largest and smallest numbers you've seen so far. With each new number, after adding it to the $total, see if it qualifies as either the new largest or smallest, and update that value if so. You can construct your own "if" statements to see if the new number is greater than the current $largest or not. Or you could use List::Util which has a min (and a max) function which return the smallest (and largest) value of the list you pass in. For instance:
So each time you consider a new number you can update the $smallest number so far to either be the current value of $smallest, or the new number:
Unfortunately because $smallest is set to 0 at the start of your program, no value above zero will ever show up as the smallest input! You could start it off with a value of 10,000 and just hope nobody enters a number bigger than that. But a better way is to start $smallest off with the largest number possible, so that the first input it sees will naturally be the smallestsofar. In Perl there is a funny notation for this largest number possible: '+inf', and for the smallest possible, minus infinity or 'inf'. Therefore you'd need to remove $smallest and $largest from where they are initialized to zero now, and add a line like:
So that the logic you use to find the largest and smallest is sure to find values that fit.
In Section
Seekers of Perl Wisdom

