do not trim valueless contents
[barcat.git] / barcat
diff --git a/barcat b/barcat
index 4c3cf8a763210ae3eb31fb7ecb41a25665da6ac0..1347cf5a5d053e282c721d6ee2669419180643a5 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -85,7 +85,7 @@ while (readline) {
        s/^\h*// unless $opt{unmodified};
        push @values, s/$valmatch/\n/ && $1;
        push @order, $1 if length $1;
-       if (defined $opt{trim}) {
+       if (defined $opt{trim} and defined $1) {
                my $trimpos = abs $opt{trim};
                if ($trimpos <= 1) {
                        $_ = substr $_, 0, 1;
@@ -181,11 +181,13 @@ if ($opt{stat}) {
                $opt{hidemax} ||= @lines;
                printf '%s of ', sum(@values[$opt{hidemin} - 1 .. $opt{hidemax} - 1]) // 0;
        }
-       my $total = sum @order;
-       printf '%s total', $total;
-       printf ' in %d values', scalar @values;
-       printf ' (%s min, %*.*f avg, %s max)',
-               $order[-1], 0, 2, $total / @order, $order[0];
+       if (@order) {
+               my $total = sum @order;
+               printf '%s total', $total;
+               printf ' in %d values', scalar @values;
+               printf ' (%s min, %*.*f avg, %s max)',
+                       $order[-1], 0, 2, $total / @order, $order[0];
+       }
        say '';
 }