Xref: utzoo alt.sources:3106 comp.misc:11314 alt.folklore.computers:9234 Path: utzoo!utgpu!cs.utexas.edu!uunet!bu.edu!nntp-read!composer From: composer@chem.bu.edu (Jeff Kellem) Newsgroups: alt.sources,comp.misc,alt.folklore.computers Subject: Re: Acronym lookup tool Summary: Acronym lookup tool in Perl Keywords: acronyms, database, lookup, perl Message-ID: Date: 2 Feb 91 19:50:29 GMT References: <1991Jan29.194237.12551@cs.utk.edu> Sender: news@bu.edu.bu.edu Reply-To: composer@chem.bu.edu Followup-To: alt.sources Organization: Boston University Chemistry Department Lines: 140 In-reply-to: de5@ornl.gov's message of 29 Jan 91 19:42:37 GMT Dave, Thanks for posting the acronym database stuff. For those that have Perl, below is a quick rewrite of Dave's acronym lookup tool in Perl. It's not fancy, just a quick translation to Perl. Same logic, etc.. The perl script is also it's own man page (thanks to Larry Wall for the nroff/perl trickery). The only thing I added was to look for the acronyms database in a few default locations, along with having the ACRON environment variable override the defaults. The Perl code could look better, but hey.. it's just a quick translation. ;-) Enjoy... -jeff Jeff Kellem Internet: composer@chem.bu.edu ===CUT HERE===whats (in Perl)=== #!/usr/local/bin/perl 'di'; 'ig00'; # # file: whats (or whats.pl or whats.perl) # # usage: whats [ acronym [defn...]] # See man page after __END__ line # $ACRON = $ENV{'ACRON'} || (-f '/usr/local/lib/acronyms' && '/usr/local/lib/acronyms') || (-f './acronyms' && './acronyms') || (-f './acron' && './acron'); ($me = $0) =~ s|.*/||; die "$me: Can't find acronym file\n" unless $ACRON; $lookup = shift || &input('What is what? '); $lookup =~ tr/a-z/A-Z/; $def = join(" ", @ARGV); # gather up rest of args open ACRON || die "$me: Can't open acronym file: $!\n"; while () { next unless /^$lookup\s*-/o; push(@found, $_); # or could do $found .= $_; $count++; } close ACRON; if (!$def && @found) { print @found; exit; } elsif (@found) { # or $#found+1 print scalar(@found), " occurrences found.\n", @found; if (&input("Still want to add $lookup? ") !~ /^y$/oi) { exit; } } $def = $def || &input("What does $lookup stand for? ") || exit; $lookup = sprintf("%-8s- $def", $lookup); open(ACRON, ">> $ACRON") || die "$me: Can't append to $ACRON: $!\n"; print ACRON "$lookup\n"; close ACRON; print "$lookup\n"; sub input { print @_[0]; chop($_ = ); $_; } ############################################################### # These next few lines are legal in both Perl and nroff. .00; # finish .ig 'di \" finish diversion--previous line must be blank .nr nl 0-1 \" fake up transition to first page again .nr % 0 \" start at page 1 '; __END__ ##### From here on it's a standard manual page ##### .TH WHATS 1 "February 2, 1991" .AT 3 .SH NAME whats \- lookup acronym/abbreviation in database .SH SYNOPSIS .B whats [acronym [defn...]] .SH DESCRIPTION .IR Whats , without any arguments, prompts for an acronym to look up. With one argument, .I whats prints all entries from the database that match the argument. If no matches are found, .I whats prompts for expansion of the acronym or abbreviation. With more than one argument, .I whats scans the database for entries matching the first argument. If any matches are found, .I whats prints the matching entries and asks if the remaining arguments should be added as a new entry. If no matches are found, a new entry is created for the first argument with the remaining arguments forming the expansion. .SH ENVIRONMENT .IP ACRON The location of the acronym database. Overrides any default locations. .SH FILES The acronym database is searched for in the following order: $ACRON /usr/local/lib/acronyms ./acronyms ./acron .SH AUTHOR Original shell script written by: .br Dave Sill (dsill@nswc-oas.arpa) (de5@ornl.gov as of 6/90) Naval Surface Warfare Center (NSWC), Dahlgren, VA .PP Perl translation written by: .br Jeff Kellem (composer@chem.bu.edu), 2 Feb 1991 .SH "SEE ALSO" .SH BUGS Not blindingly fast. The Perl version should work on any system that runs Perl. .PP The Perl version is basically just a straight translation of the original shell script. .PP The Perl version should probably be reorganized a tiny bit.