

&readCMUDict;
#&postreaddebug;
while ($line = <>) {
   @tokens = parseline($line);
   foreach $token (@tokens) {
      if ($megalist{$token}) {
         print "$megalist{$token}\n";
      } else {
         print "!!!$token\n";
      }
   }
}

sub postreaddebug{
   print "Dictionary successfully read.\n";
   print $megalist{"HAPPY"}; print "\n";
   print $megalist{"PHONETICS"}; print "\n";
}

sub readCMUDict {
   open (CMUD, "d:\\linguist\\lexica\\cmu-concise.txt");
   while ($line = <CMUD>) {
      ($word, $repeat, $transcription) = parseCMUentry($line);
      if ($repeat) {
         $megalist{$word} .=  " || " . $transcription;
      } else {
         $megalist{$word} = $transcription;
      }
   }
   close CMUD;
}

sub parseCMUentry {
   $line = @_[0];
   $line =~ /\s*(\w*)(\(\d\))*\s+(.*)/;
   return ($1, $2, $3);
}

sub parseline {
   $line = @_[0];
   chomp $line;
   @tokenlist = "";     # works?
   while ($line) {
      $line =~ /\s*([^\'\-\w]*)([\'\-\w]*)\s*(.*)/;
      if ($1) { push @tokenlist, ($1) };
      if ($2) { push @tokenlist, ("\U$2") };
      $line = $3;
#      print "1: $1\n";
#      print "2: $2\n";
#      print "3: $3\n\n";
   }
   print ("==", join (" ", @tokenlist));
   return @tokenlist;
}

sub isPunctuation {
   my $token = @_;
   return ($token =~ /\W/);
}

