report variables unformatted on trailing #
[barcat.git] / barcat
diff --git a/barcat b/barcat
index 6dbddd97910941e84542173cfff807318eaa906a..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,
@@ -383,19 +383,21 @@ sub show_stat {
 
 sub varfmt {
        my ($fmt, $vars) = @_;
-       $fmt =~ s[\$\{ (\w+) (?<cmd>; (?: [^{}]+ | \{.*?\} )*)? \}]{
-               local $_ = $vars->{$1};
+       $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};
-                       if ($+{cmd}) {
-                               eval $+{cmd};
-                               warn "Error in \$$1 report: $@" if $@;
+                       $_ = $opt{'value-format'}->($_) if $format;
+                       if ($cmd) {
+                               eval $cmd;
+                               warn "Error in \$$name report: $@" if $@;
                        }
                        $_;
                }
                else {
-                       warn "Unknown variable \$$1 in report\n";
-                       "\$$1";
+                       warn "Unknown variable \$$name in report\n";
+                       "\$$name";
                }
        }eg;
        return $fmt;