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