|
1 #!/usr/bin/perl |
|
2 |
|
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 |
|
7 |
|
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/. |
|
11 |
|
12 $min = 1.7976931348623157E+308; |
|
13 $max = 2.2250738585072014E-308; |
|
14 $sum = $num = 0; |
|
15 |
|
16 while(<>) { |
|
17 chomp; |
|
18 |
|
19 @nums = split(/[\s,]+/, $_); |
|
20 next if($#nums < 0); |
|
21 |
|
22 $num += scalar @nums; |
|
23 foreach (@nums) { |
|
24 $min = $_ if($_ < $min); |
|
25 $max = $_ if($_ > $max); |
|
26 $sum += $_; |
|
27 } |
|
28 } |
|
29 |
|
30 if($num) { |
|
31 $avg = $sum / $num; |
|
32 } else { |
|
33 $min = $max = 0; |
|
34 } |
|
35 |
|
36 printf "%d\tmin=%.2f, avg=%.2f, max=%.2f, sum=%.2f\n", |
|
37 $num, $min, $avg, $max, $sum; |
|
38 |
|
39 # end |