From: Mischa POSLAWSKY Date: Sat, 7 Sep 2019 18:36:44 +0000 (+0200) Subject: minor code cleanup for human formatting X-Git-Tag: v1.04~8 X-Git-Url: http://git.shiar.nl/barcat.git/commitdiff_plain/74afb3df155890f510e3d129472d80768243a181 minor code cleanup for human formatting --- diff --git a/barcat b/barcat index 40f332d..00a2173 100755 --- a/barcat +++ b/barcat @@ -56,7 +56,7 @@ GetOptions(\%opt, $opt{width} ||= $ENV{COLUMNS} || 80; $opt{color} //= -t *STDOUT; # enable on tty $opt{trim} *= $opt{width} / 100 if $opt{trimpct}; -$opt{units} = $opt{'human-readable'} && ['', qw( k M G T P E Z Y y z a f p n μ m )]; +$opt{units} = [split //, ' kMGTPEZYyzafpnμm'] if $opt{'human-readable'}; $opt{anchor} //= qr/\A/; $opt{'value-length'} = 6 if $opt{units}; @@ -136,7 +136,7 @@ sub sival { sprintf('%*.*f%*s', $float ? 5 : 3, $float, # length and tenths $_[0] / 1000 ** $unit, # number - $float ? 1 : 3, # unit size + $float ? 0 : 3, # unit size $#{$opt{units}} >> 1 < abs $unit ? "e$unit" : $opt{units}->[$unit] ); }