- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl getpwent Function
Description
This function returns the next password entry from the /etc/passwd file. This is used in combination with the setpwent and endpwent functions to iterate over the password file. In a list context, returns
($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwent;
Syntax
Following is the simple syntax for this function −
getpwent
Return Value
This function returns username in scalar context and user record (name, password, user ID, group ID, quote, comment, real name, home directory, shell) in list context.
Example
Following is the example code showing its basic usage −
#!/usr/bin/perl while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwent()) { print "Name = $name\n"; print "Password = $passwd\n"; print "UID = $uid\n"; print "GID = $gid\n"; print "Quota = $quota\n"; print "Comment = $comment\n"; print "Gcos = $gcos\n"; print "HOME DIR = $dir\n"; print "Shell = $shell\n"; }
When above code is executed, it produces the following result −
Name = root Password = x UID = 0 GID = 0 Quota = Comment = Gcos = root HOME DIR = /root Shell = /bin/bash Name = bin Password = x UID = 1 GID = 1 Quota = Comment = Gcos = bin HOME DIR = /bin Shell = /sbin/nologin . . . Name = com Password = x UID = 501 GID = 501 Quota = Comment = Gcos = HOME DIR = /home/com Shell = /bin/bash Name = railo Password = x UID = 497 GID = 495 Quota = Comment = Gcos = HOME DIR = /opt/railo
perl_function_references.htm
Advertisements