From eecc64aa47590838bfc532da0bdcca73fc253a67 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 10 May 2020 01:10:34 +0530 Subject: Print error message if no match is found --- pictor.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pictor.pl b/pictor.pl index 608c879..f271d9f 100755 --- a/pictor.pl +++ b/pictor.pl @@ -47,6 +47,9 @@ unveil() or pledge( qw( rpath )) or die "Unable to pledge: $!"; +# $total_acronyms will hold the total number of acronyms we find. +my $total_acronyms = 0; + # Search for acronym in every file. foreach my $fn (@files) { open my $fh, '<', $fn or @@ -62,11 +65,16 @@ foreach my $fn (@files) { # mess with \t. This regex matches when $line starts with # "$term\t". We replace \t with ": " before printing to make # the input neat. - print $line =~ s/\t/: /r if + print $line =~ s/\t/: /r and + $total_acronyms++ if ($line =~ /^\Q${term}\E\t/i); } } -# drop pledge permissions +# Print an error message if we don't find any match. +say STDERR "I don't know what '$term' means!" and + exit 1 unless + $total_acronyms; + pledge() or die "Unable to pledge: $!"; -- cgit 1.4.1-2-gfad0