From 7134010f98a9ca0ef86211deab4f5c9f059a04df Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 23 May 2021 16:19:21 -0700 Subject: [PATCH] Minor clean-up of bash faq --- modules/bashfaq.pl | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/bashfaq.pl b/modules/bashfaq.pl index 99cb209e..c7832f34 100755 --- a/modules/bashfaq.pl +++ b/modules/bashfaq.pl @@ -7,7 +7,7 @@ my $query = "@ARGV"; print "Usage: faq \n" and exit 0 if not length $query; -my (%faq, $id, $rcpt, $output); +my (%faq, $match); open(FILE, "< bashfaq.txt") or print "Can't open Bash FAQ: $!" and exit 1; @@ -26,23 +26,21 @@ if ($query =~ / >/) { } if (exists $faq{$query}) { - $id = $query; - $output = $faq{$id}; + $match = $query; } else { foreach my $key (keys %faq) { if ($faq{$key} =~ /$query/i) { - $id = $key; - $output = $faq{$key}; + $match = $key; last; } } } -if (defined $output) { - $id = sprintf "%03d", $id; - $output = "https://mywiki.wooledge.org/BashFAQ/$id -- $output\n"; - $output = "$rcpt: $output" if length $rcpt; - print $output; +if ($match) { + my $id = sprintf "%03d", $match; + my $output = "https://mywiki.wooledge.org/BashFAQ/$id -- $faq{$match}"; + print "$rcpt: " if $rcpt; + print "$output\n"; } else { print "No matches found at https://mywiki.wooledge.org/BashFAQ\n"; }