Hi folks,
Trying to make learning of German adjectives easier for me ( and to learn
Perl, of course :-) ) I've decided to create a small dictionary in Perl.. Is
using a hash of lists a good approach to solve the problem? 

- I've created several fairly small dictionary files - each line in them
looks more or less like that:
'aufgedreht: lit up, activated, attracted to, interested in'
- the name of a file is the command line parameter for my program
- reading entries:
open(FILEH,$filename) or die "Can't open file: $filename\n";

my $entry;
my $rest;
my @fields;

#------------------------------------------------------------------
#  read entries in the dictionary file
#------------------------------------------------------------------
while(defined($line = <FILEH>)) {
   $line =~ s/\n$//;
   ($entry, $rest) = split(/:\s*/, $line, 2);
   @fields = split(',', $rest);
   $HoL{$entry} = [ @fields ];
}

- main loop ( exit if new line ):
my $toBf;
print "Enter a word to be searched: \n";
while ($toBf = <STDIN>) {
   if ( $toBf =~ /^\n$/) {
      die "Bye, bye!\n";
   }
   chomp($toBf);
   find_entry(\%HoL, $toBf);
   print "Enter a word to be searched: \n";
}

#------------------------------------------------------------------
#  find_entry
#------------------------------------------------------------------
sub find_entry {
   my $href = shift;
   my $key = shift;

   if ( exists(${$href}{$key}) ) {
      print_elem($href,$key);
   } else {
      print "\'$key\' was not found in the dictionary. Sorry!\n";
   }
}

I would be really thankful for any comments/advices...
Ela

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to