michael@0: #!/usr/bin/perl michael@0: michael@0: # michael@0: # Treat each line as a sequence of comma and/or space delimited michael@0: # floating point numbers, and compute basic statistics on them. michael@0: # These are written to standard output michael@0: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: $min = 1.7976931348623157E+308; michael@0: $max = 2.2250738585072014E-308; michael@0: $sum = $num = 0; michael@0: michael@0: while(<>) { michael@0: chomp; michael@0: michael@0: @nums = split(/[\s,]+/, $_); michael@0: next if($#nums < 0); michael@0: michael@0: $num += scalar @nums; michael@0: foreach (@nums) { michael@0: $min = $_ if($_ < $min); michael@0: $max = $_ if($_ > $max); michael@0: $sum += $_; michael@0: } michael@0: } michael@0: michael@0: if($num) { michael@0: $avg = $sum / $num; michael@0: } else { michael@0: $min = $max = 0; michael@0: } michael@0: michael@0: printf "%d\tmin=%.2f, avg=%.2f, max=%.2f, sum=%.2f\n", michael@0: $num, $min, $avg, $max, $sum; michael@0: michael@0: # end