in reply to Re: I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated.
in thread I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated.

Personally, I'd want to set the min and max to undef.

I then have a min/max function that skips over undefs in the input list (rather than treating undef as zero). If everything in the list is undef, then the result is undef. Otherwise the min/max of the defined values is returned.

  • Comment on Re^2: I am stuck on how to print the largest and smallest numbers from user inputted values. Any help is appreciated.
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: 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 20:10 UTC

    Yeah, then you don't even really need to set them to undef, since as others have shown in their code there is already a decent way to test if it's the first iteration. Or you can just prime the values from the first input to begin with and start iterating from the second value. What I was describing was a more general idea that has the benefit of simplicity and avoiding an extra conditional check in every iteration.