#!/usr/bin/perl use Getopt::Std; getopts("u:mw:d:"); #defualt file locations over ride with option -d $wordlist = "/usr/share/lib/dict/words"; $database = "$ENV{HOME}/.word_db"; #option -u(nscramble) ... if($opt_u){ #open default if not specified open(IN, $opt_d ? "<$opt_d" : "<$database"); #build the lookup table while(){ ($value, $key) = split /:/; chomp $key; $hash{$key} = $value; } #arange the letters to match format of database $sorted = join "",sort split//,$opt_u; #display unscrambled word print $hash{$sorted}."\n"; } #build the database file, -m(ake) elsif($opt_m){ open(IN, $opt_w ? "<$opt_w" : "<$wordlist"); open(OUT, $opt_d ? ">$opt_d" : ">$database"); #write lookup table, word:sorted letters while() { chomp; $sorted = join "",sort split//; print OUT "$_:$sorted\n"; } } else { print "Usage: ./$0 [-m] [-w[wordlist]] [-d [database]][-u scrambledword]\n"; }