in reply to Need help converting!!!
use strict; use warnings; use IO::Prompt::Hooked; use List::Util qw(max min sum); my %prompt_options = ( message => 'input a positive integer (or a negative integer to st +op)', validate => qr/^-?\d+$/, error => "Input must be a positive integer\n", escape => qr/^-\d/, ); my @input_array; push @input_array, $_ while (defined ($_ = prompt(%prompt_options))); die "No inputs were entered\n" if (!@input_array) ; print "\n\n\n"; print 'Highest input: ', max( @input_array ), "\n"; print 'Lowest input: ', min( @input_array ), "\n"; print 'average: ', sum( @input_array ) / @input_array, "\n";
This approach is wasteful of both computer time and memory, but neither should be a problem with the small amount of data that a human operator is likely to enter. The advantage is that this is easy to write and you can hve confidence in the computations done by the modules.
|
|---|