Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Need help converting!!!

by BillKSmith (Monsignor)
on Nov 16, 2015 at 15:34 UTC ( [id://1147810]=note: print w/replies, xml ) Need Help??


in reply to Need help converting!!!

If you interested in the operator interface more than the details of the algorithm, use of perl modules can simplify the progam and provide improved error reporting/recovery.
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.

Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1147810]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found