Skip to Content
Programming Perl, 4th Edition
book

Programming Perl, 4th Edition

by Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
February 2012
Intermediate to advanced
1184 pages
37h 17m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 4th Edition

getpwent

getpwent
setpwent
endpwent

These functions conceptually iterate through your /etc/passwd file, though this may involve the /etc/shadow file if you’re the superuser and are using shadow passwords; it may get a lot fancier than that if you’re using some database- or network-based login system. The return value in list context is:

#  0     1       2    3    4      5        6     7    8
($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwent();

Some machines may use the quota and comment fields for purposes other than their named 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. The User::pwent module supports a by-name interface to this function. See getpwent(3).

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Perl, 3rd Edition

Programming Perl, 3rd Edition

Larry Wall, Tom Christiansen, Jon Orwant
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes
Learning Perl, 8th Edition

Learning Perl, 8th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9781449321451Supplemental ContentErrata Page