Programming Perl

Programming PerlSearch this book
Previous: 3.2.43 getcChapter 3
Functions
Next: 3.2.45 getgrgid
 

3.2.44 getgrent

getgrent
setgrent
endgrent

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

($name, $passwd, $gid, $members)

where $members contains a space-separated list of the login names of the members of the group. To set up a hash for translating group names to gids, say this:

while (($name, $passwd, $gid) = getgrent) {
    $gid{$name} = $gid;
}

In scalar context, getgrent returns only the group name.


Previous: 3.2.43 getcProgramming PerlNext: 3.2.45 getgrgid
3.2.43 getcBook Index3.2.45 getgrgid