prepare regex to match values
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Sep 2019 14:17:35 +0000 (16:17 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Sep 2019 18:16:38 +0000 (20:16 +0200)
Code cleanup, slight speedup.

barcat

diff --git a/barcat b/barcat
index 89b110fe2ca04ecbf8fb4421190346020687a02d..05502ea068c5a67dd24976e5eb34d3654c4f5d5f 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -68,10 +68,11 @@ my (@lines, @values);
 my $anchor = !defined $opt{field} ? qr/\A/ :
        $opt{field} =~ /^[0-9]+$/ ? qr/(?:\S*\h+){$opt{field}}\K/ :
        $opt{field};
+my $valmatch = qr/$anchor ( \h* -? [0-9]* \.? [0-9]+ |)/x;
 while (readline) {
        s/\r?\n\z//;
        s/^\h*// unless $opt{unmodified};
-       push @values, s/$anchor ( \h* -? [0-9]* \.? [0-9]+ |)/\n/x && $1;
+       push @values, s/$valmatch/\n/ && $1;
        if (defined $opt{trim}) {
                my $trimpos = abs $opt{trim};
                if ($trimpos <= 1) {