},
'human-readable|H!',
'sexagesimal!',
+ 'reformat!',
'interval|t:i',
'trim|length|l=s' => sub {
my ($optname, $optval) = @_;
$opt{input} = (@ARGV && $ARGV[0] =~ m/\A[-0-9]/) ? \@ARGV : undef
and undef $opt{interval};
-$opt{'sum-format'} = sub { sprintf '%.8g', $_[0] };
$opt{'calc-format'} = sub { sprintf '%*.*f', 0, 2, $_[0] };
$opt{'value-format'} = $opt{sexagesimal} ? sub {
my $s = abs($_[0]) + .5;
$#{$opt{units}} * 1.5 < abs $unit ? sprintf('e%d', $unit) :
$opt{units}->[$unit/3] # suffix
);
-};
+} and $opt{reformat}++;
+$opt{'value-format'} ||= sub { sprintf '%.8g', $_[0] };
my (@lines, @values, @order);
and $. % $opt{interval} == 0;
}
-if ($opt{'zero-missing'}) {
- push @values, (0) x 10;
-}
-
$SIG{INT} = 'DEFAULT';
sub color {
if (length $val) {
$val = sprintf("%*s", $lenval,
- $opt{'value-format'} ? $opt{'value-format'}->($val) : $val
+ $opt{reformat} ? $opt{'value-format'}->($val) : $val
);
color($color) for $val;
}
$linemin += @lines;
$linemax = @lines - $linemax;
}
- printf '%.8g of ', $opt{'sum-format'}->(
+ printf '%.8g of ', $opt{'value-format'}->(
sum(grep {length} @values[$linemin .. $linemax]) // 0
);
}
if (@order) {
my $total = sum @order;
- printf '%s total', color(1) . $opt{'sum-format'}->($total) . color(0);
+ printf '%s total', color(1) . $opt{'value-format'}->($total) . color(0);
printf ' in %d values', scalar @order;
printf ' over %d lines', scalar @lines if @order != @lines;
printf(' (%s min, %s avg, %s max)',
- color(31) . ($opt{'value-format'} || sub {$_[0]})->($order[-1]) . color(0),
- color(36) . ($opt{'value-format'} || $opt{'calc-format'})->($total / @order) . color(0),
- color(32) . ($opt{'value-format'} || sub {$_[0]})->($order[0]) . color(0),
+ color(31) . ($opt{reformat} ? $opt{'value-format'} : sub {$_[0]})->($order[-1]) . color(0),
+ color(36) . ($opt{reformat} ? $opt{'value-format'} : $opt{'calc-format'})->($total / @order) . color(0),
+ color(32) . ($opt{reformat} ? $opt{'value-format'} : sub {$_[0]})->($order[0]) . color(0),
);
}
say '';