http://www.perlmonks.org?node_id=934875

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks I have a very big dictionary of phrases (millions of entries) and when I read it to hash I'm out of memory. I want to store it once in a local memory and every time I can use it efficiently as my dictionary. What modules do you recommend for : 1- tie it in the local memory, and 2- accessing it efficiently. I use this code to read my dictionary:
sub read_dict{ my $file=shift; my %dict; open( FILE, "<:encoding(utf5)", $file ); while (<FILE>) { chomp; my ($p1, $p2) = split /\t/; chomp ($p1, $p2); push( @{$dict{$p1}}, $p2 ); } close FILE; return %dict; }
Note that while I read it I run out of memory so I need to be able to read each and store instead of reading the whole dictionary. later I use this hash to look up for many many entries in my text. Thanks for your hints and code snippets in advance.