Next | Lightweight Databases | 40 |
billg 666 xyPXkPQTjCjnUGates William
mjd 119 A12FMTJGN5wpYDominus Mark Jason
longuser123453OUbq7V0pV9doLongusername-EarwiggFeatherstonehaughs
larry 1 ..qQYY3gYY0yAWall Larry
...
Code to search for a user now looks like this:
sub find_user { my ($fh, $user) = @_; seek $fh, 0, SEEK_SET; while (read($fh, my($rec), 64) == 64) { my (@field) = unpack "A8 A5 A13 A20 A18", $rec; next unless $user eq $field[0]; return @field; } return; }
unpack gets a format string that describes the data format
A8 is a space-padded alphabetic field of length 8
Trailing spaces are trimmed off
a8 is similar, but NUL-padded ("\0")
Next | Copyright © 2003 M. J. Dominus |