compile regular expression to -f (without /x)
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Sep 2019 14:39:29 +0000 (16:39 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 7 Sep 2019 18:16:38 +0000 (20:16 +0200)
Reports syntax errors immediately.

barcat

diff --git a/barcat b/barcat
index 3e1980d6aabef20521353281e5c4e0d167a34c3f..6d5610996a00f7b7c614d67a26956ac162fe2ff4 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -18,7 +18,10 @@ GetOptions(\%opt,
        'color|c!',
        'C' => sub { $opt{color} = 0 },
        'field|f=s' => sub {
-               $opt{anchor} = /^[0-9]+$/ ? qr/(?:\S*\h+){$_}\K/ : $_ for $_[1];
+               eval {
+                       local $_ = $_[1];
+                       $opt{anchor} = /^[0-9]+$/ ? qr/(?:\S*\h+){$_}\K/ : qr/$_/;
+               } or die "$@ for option $_[0]\n";
        },
        'human-readable|H!',
        'interval|t:i',