Next Lightweight Databases 63

Indexing with Tie::File

        my %index;
        my $NEXT_UNREAD = 0;
        sub find_user {
          my ($file, $user) = @_;
          my $rec;
          until (exists $index{$user}) {
            $rec = $file->[$NEXT_UNREAD];
            return unless defined $rec;
            my ($u) = unpack "A8", $rec;
            $index{$u} = $NEXT_UNREAD;
            $NEXT_UNREAD++;
          }
          return unpack "A8 A5 A13 A20 A18", $file->[$index{$user}];
        }


Next Copyright © 2003 M. J. Dominus