start page | rating of books | rating of authors | reviews | copyrights

Programming Perl

Programming PerlSearch this book
Previous: 3.2.60 getprotoent Chapter 3
Functions
Next: 3.2.62 getpwnam
 

3.2.61 getpwent

getpwent setpwent endpwent

These functions do the same thing as their like-named system library routines - see getpwent (3). They iterate through your /etc/passwd file (or its moral equivalent coming from some server somewhere). The return value in list context is:

($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell)

Some machines may use the quota and comment fields for other purposes, but the remaining fields will always be the same. To set up a hash for translating login names to uids, say this:

while (($name, $passwd, $uid) = getpwent) {     $uid{$name} = $uid; }

In scalar context, getpwent returns only the username.


Previous: 3.2.60 getprotoent Programming Perl Next: 3.2.62 getpwnam
3.2.60 getprotoent Book Index 3.2.62 getpwnam