Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/usr/bin/perl |
michael@0 | 2 | |
michael@0 | 3 | # |
michael@0 | 4 | # Treat each line as a sequence of comma and/or space delimited |
michael@0 | 5 | # floating point numbers, and compute basic statistics on them. |
michael@0 | 6 | # These are written to standard output |
michael@0 | 7 | |
michael@0 | 8 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 9 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 10 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 11 | |
michael@0 | 12 | $min = 1.7976931348623157E+308; |
michael@0 | 13 | $max = 2.2250738585072014E-308; |
michael@0 | 14 | $sum = $num = 0; |
michael@0 | 15 | |
michael@0 | 16 | while(<>) { |
michael@0 | 17 | chomp; |
michael@0 | 18 | |
michael@0 | 19 | @nums = split(/[\s,]+/, $_); |
michael@0 | 20 | next if($#nums < 0); |
michael@0 | 21 | |
michael@0 | 22 | $num += scalar @nums; |
michael@0 | 23 | foreach (@nums) { |
michael@0 | 24 | $min = $_ if($_ < $min); |
michael@0 | 25 | $max = $_ if($_ > $max); |
michael@0 | 26 | $sum += $_; |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | if($num) { |
michael@0 | 31 | $avg = $sum / $num; |
michael@0 | 32 | } else { |
michael@0 | 33 | $min = $max = 0; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | printf "%d\tmin=%.2f, avg=%.2f, max=%.2f, sum=%.2f\n", |
michael@0 | 37 | $num, $min, $avg, $max, $sum; |
michael@0 | 38 | |
michael@0 | 39 | # end |