Next Lightweight Databases 85

Indexing Revisited

        open PASSWD, "<", "/etc/passwd" or die $!;
        tie %by_name, 'DB_File', "./pw_aux", O_CREAT|O_RDWR, 0666
          or die $!;
        tie %by_uid, 'DB_File', "./pw_uid", O_CREAT|O_RDWR, 0666
          or die $!;
        make_index(\*PASSWD, \%by_name, 
                   sub { (split /:/, $_[0], 2)[0] },
                  );
        make_index(\*PASSWD, \%by_uid, 
                   sub { (split /:/, $_[0], 3)[1] },
                  );
        print find(\*PASSWD, \%by_name, 'mjd');
        print find(\*PASSWD, \%by_uid, 119);


Next Copyright © 2003 M. J. Dominus