use WordList; tie %h, "WordList", "/usr/dict/words"; if (exists $h{foo}) { print "It's there!" } if ($h{foo}) { print "There too!" } print keys %h; #### package WordList; use Search::Dict; use strict; sub TIEHASH { my($class, $dictionary)=@_; open(D, $dictionary) || die "Can't open $dictionary: $!"; my $self={ file => do { *D }, 'each' => undef }; bless $self, $class; } sub EXISTS { my($self, $key)=@_; my $o=look $self->{file}, $key, 0, 0; local chomp($_=readline $self->{file}); if ($_ eq $key) { return 1; } return; } sub FETCH { $_[0]->EXISTS($_[1]); } sub FIRSTKEY { $_[0]->{'each'}=0; $_[0]->NEXTKEY; } sub NEXTKEY { my($self)=@_; seek($self->{file}, $self->{each}, 0) || warn; local $_=readline $self->{file}; if (! defined $_) { return $self->{each}=undef; } $self->{each}=tell($self->{file}); chomp; return $_; } sub STORE {} sub DELETE {} sub CLEAR {} 1;