#!perl
# Simple script to check for words of a certain length starting with a certain
# letter from the system dictionary file. Pretty silly, actually.
# Created 10-2000 by Andrew Greenburg <andrew@analogmarketing.net>.
 
# Where is our dictionary file?
$dictfile = "/usr/dict/words";
 
# Let's make sure that we have command line arguments.
if (!$ARGV[1]) {
    die "Usage: $0 <First letter> <Number of letters>\n";
}
 
# Clean them up.
chomp ($firstletter = $ARGV[0]);
chomp ($numberletters = $ARGV[1]);
 
# Make it case-insensitive.
$firstletter = lc($firstletter);
 
# Let's make sure that our arguments make sense.
if (!($firstletter =~ /^[a-z]/)) {
    print "Not a letter\!\n";
    die "Usage: $0 <First letter> <Number of letters>\n";
}
if (!($numberletters =~ /^[0-9]/)) {
    print "Not a number\!\n";
    die "Usage: $0 <First letter> <Number of letters>\n";
}
 
# Open the dictionary file for reading.
open (DICTIONARY, "$dictfile");
while (<DICTIONARY>) {
 
    # Make it case insensitive and kill those pesky newlines.
    chomp($currentword = lc($_));
 
    # Check for our first letter and length.
    $currentword =~ /^$firstletter/ || next;
    if (!(length($currentword) == $numberletters)) {
        next;
    }
 
    # Print it, if we made it through all that.
    print "$currentword\n";
}
 
# That wasn't so bad, was it?
close (DICTIONARY);
exit 0;