Path: utzoo!attcan!uunet!mailrus!ncar!tank!gargoyle!chinet!john From: john@chinet.chi.il.us (John Mundt) Newsgroups: comp.lang.perl Subject: Re: Would like to emulate an array of pointers to a structure Message-ID: <1990Mar28.154934.6689@chinet.chi.il.us> Date: 28 Mar 90 15:49:34 GMT References: <12170003@hpccc.HP.COM> Reply-To: john@chinet.chi.il.us (John Mundt) Organization: Chinet - Chicago Public Access UNIX Lines: 27 In article <12170003@hpccc.HP.COM> okamoto@hpccc.HP.COM (Jeff Okamoto) writes: > ... >I'm trying to do some manipulations on the password file. What I'd like >to be able to do is to somehow be able to reference one entire line of >it with a single index value. I know I can do this with an array of >entire password file lines, but I don't want to keep having to split >each line while searching for a particular entry (e.g., login name). > >The C equivalent would be an array of pointers to a structure. Is >there an easy (and intuitive!) method for doing what I'm trying to do? > Try using getpwent() and its associated functions, which allow you to do just what you are talking about, and which store things in a struct which has split the different fields out into structure members. It does it one at a time, but you could create an array of this struct and fill it from the password file once and play with each line at your leisure. Alternatively, there is a reset function to these functions setpwent() which rewinds the file and starts again. Don't forget to call endpwent() when you are all done. -- --------------------- John Mundt Teachers' Aide, Inc. P.O. Box 1666 Highland Park, IL john@admctr.chi.il.us *OR* fred@teacha.chi.il.us (312) 998-5007 (Day voice) || -432-8860 (Answer Mach) && -432-5386 Modem