summaryrefslogtreecommitdiff
path: root/var
diff options
context:
space:
mode:
Diffstat (limited to 'var')
-rwxr-xr-xvar17
1 files changed, 6 insertions, 11 deletions
diff --git a/var b/var
index 08b75b6..30c638a 100755
--- a/var
+++ b/var
@@ -3,13 +3,8 @@
require 'trollop'
-def usage
- STDERR.write "./stddev [-r <d>] < <one number per line>\n"
- exit 1
-end
-usage if not [0,2].include? ARGV.size
-
-opts = Trollop::options do
+cfg = Trollop::options do
+ banner "stddev [-r <d>] < <one number per line>"
opt :round, "Number of digits after decimal point.", :type => :int, :default => -1
end
@@ -18,10 +13,10 @@ sum = 0.0
i = 0
cached = []
while line=STDIN.gets
- v = line.strip.to_f
+ v = line.to_f
sum += v
cached << v
- i +=1
+ i +=1
end
avg = sum/i.to_f
@@ -31,8 +26,8 @@ cached.each { |v|
var += (avg - v)**2
}
-if opts[:round] >= 0
- puts var.round opts[:round]
+if cfg[:round] >= 0
+ puts var.round cfg[:round]
else
puts var
end