in reply to Best way to search flat-file database
The "best" way depends on many factors and frankly speaking in your case I don't think it matters much. The passwd file is not too big. I am not going to code it for you I'll give you some hints instead.
You’re not really clear on the type of user interface needed. I’ll assume the command line will be fine.
The Unix passwd file is structured, it consists of records, separated by a colon. I assume a unique key for each record in the passwd file, i.e. the first column.
Apparently the user inputs a name for which you want to search the file?
Each line is a record, use for example
For each line:
@fields = split(/:/, $record);
to get the individual fields. Store the stuff in some data structure (e.g. Array of Hashes, Hash of Hashes).
You might want to add some error handling for incorrect user input.
You might want to combine/leave out steps to improve the solution.
|
|---|