report variables unformatted on trailing #
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 20 Nov 2022 23:43:23 +0000 (00:43 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 22 Nov 2022 23:06:47 +0000 (00:06 +0100)
More syntax stolen from exiftool.

barcat

diff --git a/barcat b/barcat
index e02ce4ed09e9c7f47f53e00a7eda3801cb8fdc47..a86f74f4343bf3676e8b771a1e7ea4804a55c831 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -365,8 +365,8 @@ sub show_stat {
        }
        if (@order) {
                my $total = sum @order;
-               my $fmt = '${sum;color(1)} total in ${count} values';
-               $fmt .= ' over ${lines} lines' if @order != @lines;
+               my $fmt = '${sum;color(1)} total in ${count#} values';
+               $fmt .= ' over ${lines#} lines' if @order != @lines;
                $fmt .= " ($_)" for $opt{report} || ();
                print varfmt($fmt, {
                        sum => $total,
@@ -385,9 +385,10 @@ sub varfmt {
        my ($fmt, $vars) = @_;
        $fmt =~ s[\$\{( (?: [^{}]++ | \{(?1)\} )+ )\}]{
                my ($name, $cmd) = split /\s*;/, $1, 2;
+               my $format = $name !~ s/\h*\#// && $opt{reformat};
                local $_ = $vars->{$name};
                if (defined) {
-                       $_ = $opt{'value-format'}->($_) if $opt{reformat};
+                       $_ = $opt{'value-format'}->($_) if $format;
                        if ($cmd) {
                                eval $cmd;
                                warn "Error in \$$name report: $@" if $@;