O'Reilly logo

Sams Teach Yourself Perl in 21 Days, Second Edition by Rafe Colburn, Laura Lemay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

% morestats.pl
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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required