#!/usr/bin/perl -CA
-use 5.018;
+use 5.014;
use warnings;
use utf8;
use List::Util qw( min max sum );
use open qw( :std :utf8 );
-use experimental qw( lexical_subs );
our $VERSION = '1.06';
},
) or exit 64; # EX_USAGE
-$opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80;
+$opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80 unless $opt{spark};
$opt{color} //= -t *STDOUT; # enable on tty
$opt{'graph-format'} //= '-';
$opt{trim} *= $opt{width} / 100 if $opt{trimpct};
and $. % $opt{interval} == 0;
}
+if ($opt{'zero-missing'}) {
+ push @values, (0) x 10;
+}
+
$SIG{INT} = 'DEFAULT';
sub color {
$opt{palette}->[ $rel * ($#{$opt{palette}} - 1) + 1 ];
if ($opt{spark}) {
+ say '' if $opt{width} and $nr and $nr % $opt{width} == 0;
print color($color), $opt{spark}->[
!$val ? 0 : # blank
$val == $order[0] ? -1 : # max
}
if (@order) {
my $total = sum @order;
- printf '%s total', color(1) . $total . color(0);
+ printf '%s total', color(1) . sprintf('%.8g', $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)',
Commonly used after counting, for example users on the current server:
- users | sed 's/ /\n/g' | sort | uniq -c | barcat
+ users | tr ' ' '\n' | sort | uniq -c | barcat
Letter frequencies in text files:
-Gd 'node=SEARCHRESULTS&q=EXR.D.USD.EUR.SP00.A&exportType=csv' |
grep '^[12]' | barcat -f',\K' --value-length=7
-Total population history from the World Bank dataset (XML):
-External datasets, like total population in XML from the World Bank:
+Total population history in XML from the World Bank:
curl http://api.worldbank.org/v2/country/1W/indicator/SP.POP.TOTL |
xmllint --xpath '//*[local-name()="date" or local-name()="value"]' - |