#!/usr/bin/env perl use utf8; ############################################################################### # This program computes the average of a list of float values on STDIN. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use Error::Simple; use Nice::Try; use Utils; use strict; use warnings; MAIN: { my $line; my $d; my $total = 0; my $count = 0; while ($line = ) { $line = Utils::trim($line); try { $d = Utils::stod($line); $total += $d; ++$count; } catch (Error::Simple $ex) { if (length($line) > 0) { print "Can't parse input: ", $line, "\n"; } } } if ($count > 0) { print Utils::messageFormat("\{0:.16g\}", $total / $count), "\n"; } }