You can try accessing the dictionary file directly using the Search::Dict core module, assuming your dictionary is sorted. It performs a binary search through the file. Here, I've wrapped its functionality into an OO-module for convenience:
use Data::Dumper; use Search::Dict::Object; my $d = Search::Dict::Object->new( file => "/tmp/dict.txt", keyval_xfrm => sub { split /\t/ }, comp => sub { $_[0] cmp $_[1] }, # should correspond to file sort +order ); print Dumper { aaa => $d->get('aaa'), foo => $d->get('foo'), bar => $d->get('bar'), baz => $d->get('baz'), zzz => $d->get('zzz'), }; __END__ $VAR1 = { 'bar' => '789', 'baz' => '456', 'aaa' => undef, 'foo' => '123', 'zzz' => undef };

The dictionary file:
$ cat /tmp/dict.txt aho 234 bar 789 bat 567 baz 456 cut 678 foo 123 yyy 000

The Search::Dict::Object package:
package Search::Dict::Object; use warnings; use strict; use Search::Dict (); sub new { my $class = shift; my $self = bless { }, $class; $self->_init(@_); return $self; } sub _init { my $self = shift; %{ $self } = @_; unless (defined($self->{FH})) { my $file = $self->{file} || "<unspecified file>"; open($self->{FH}, "<", $file) or die("Cannot open: $file", "\n ", $!); } } sub get { my ($self, $key) = @_; return undef unless defined($key); my $FH = $self->{FH}; my $comp = $self->{comp} || sub { $_[0] cmp $_[1] }; my $keyval_xfrm = $self->{keyval_xfrm} || sub { $_ => $_ }; my $opts = { comp => $comp, $self->{keyval_xfrm} ? (xfrm => sub { chomp($_[0]); (map $keyval_xfrm->(), $_[0]) +[0] }) : (), }; if (Search::Dict::look($FH, $key, $opts) != -1) { my $entry = <$FH>; return undef unless defined($entry); chomp($entry); my ($k, $v) = map $keyval_xfrm->(), $entry; return $v if $comp->($k, $key) == 0; } return undef; } sub DESTROY { my $self = shift; close($self->{FH}) if $self->{FH}; } 1;

In reply to Re: tying a hash from a big dictionary by repellent
in thread tying a hash from a big dictionary by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.