Next | Lightweight Databases | 84 |
A typical use:
use DB_File; tie %by_name, 'DB_File', "./pw_aux", O_CREAT|O_RDWR, 0666 or die $!; open PASSWD, "<", "/etc/passwd" or die $!;
make_index(\*PASSWD, \%by_name, sub { (split /:/, $_[0], 2)[0] }, );
The key function here takes a password file line and extracts the username
We only need to call make_index once
(Until the password file changes)
After that, we can get as many fast lookups as we want:
print find(\*PASSWD, \%by_name, "mjd");
mjd:x:119:100:Mark Jason Dominus:/home/mjd:/bin/bash
Next | Copyright © 2003 M. J. Dominus |