commit be63280bffa94d1061ae4c71e59c3ac1af6e0b78
parent 327d96f76d6d3fb66ec9f1b4244b32d79a792109
Author: René Wagner <rwagner@rw-net.de>
Date: Sun, 16 Aug 2020 09:45:04 +0200
add percentage column to result set
Diffstat:
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/phosta.pl b/phosta.pl
@@ -241,7 +241,19 @@ sub result_to_stdout
my $currentlines=0;
my $skippedlines=0;
my $tb = Text::SimpleTable::AutoWidth->new();
-
+
+ push @$headers, 'percent';
+ my $sum = 0;
+ foreach (@$rows)
+ {
+ $sum += @$_[$#$_];
+ }
+ foreach (@$rows)
+ {
+ my $perc = sprintf("%.1f", (@$_[$#$_] / $sum)* 100). '%';
+ push @$_, $perc;
+ }
+
$tb->captions($headers);
foreach (@$rows)
{
@@ -256,7 +268,11 @@ sub result_to_stdout
}
}
- if (defined($opt_n)) { say "Showing top $currentlines results, skipping $skippedlines." }
+ if (defined($opt_n))
+ {
+ say "Showing top $currentlines results, skipping $skippedlines lines.";
+ say "A total of $sum images matched your criteria.";
+ }
say $tb->draw;
}