An Example: More Stats

Remember the script we did yesterday for simple statistics, where you entered numbers in one at a time, and the script calculated the count, sum, and average? Let's modify that script today to store the numbers that get entered into an array. Having the numbers around after the initial input means we can do more things with them, such as sorting them or finding the median (a different number from the mean).

Here's how the new version of the statistics script looks when it's run:

Enter a number: 4
Enter a number: 5
Enter a number: 3
						(many more numbers in here that I've deleted for space)
Enter a number: 47
Enter a number: 548
Enter a number: 54
Enter a number: 5485 Enter a number: Total count of numbers: ...

Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.