Apply value-format to all stat values; exception to keep unformatted input
indicated by an experimental reformat option.
},
'human-readable|H!',
'sexagesimal!',
},
'human-readable|H!',
'sexagesimal!',
'interval|t:i',
'trim|length|l=s' => sub {
my ($optname, $optval) = @_;
'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{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{'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
);
$#{$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);
my (@lines, @values, @order);
and $. % $opt{interval} == 0;
}
and $. % $opt{interval} == 0;
}
-if ($opt{'zero-missing'}) {
- push @values, (0) x 10;
-}
-
$SIG{INT} = 'DEFAULT';
sub color {
$SIG{INT} = 'DEFAULT';
sub color {
if (length $val) {
$val = sprintf("%*s", $lenval,
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;
}
);
color($color) for $val;
}
$linemin += @lines;
$linemax = @lines - $linemax;
}
$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;
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)',
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),
\e[90m-0:00:01\e[0m -
\e[90m-0:00:02\e[0m -
\e[31m-2:02:02\e[0m
\e[90m-0:00:01\e[0m -
\e[90m-0:00:02\e[0m -
\e[31m-2:02:02\e[0m
-\e[1m479345.21\e[0m total in 8 values over 9 lines (\e[31m-2:02:02\e[0m min, \e[36m16:38:38\e[0m avg, \e[32m111:11:11\e[0m max)
+\e[1m133:09:05\e[0m total in 8 values over 9 lines (\e[31m-2:02:02\e[0m min, \e[36m16:38:38\e[0m avg, \e[32m111:11:11\e[0m max)