Copyright © tutorialspoint.com

PERL getgrent Function


Syntax

getgrent


Definition and Usage

Iterates over the entries in the /etc/group file. Returns the following in a list context:

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

The $members scalar contains a space-separated list of the login names that are members of the group. Returns the group name only when used in a scalar context. Under Windows, consider using the Win32API::Net module.

Return Value

  • In scalr context it returns Group name.

  • In list context (Name, Password, Group ID, and member list.

Example

Try following example:

#!/usr/bin/perl

while( ($name,$passwd,$gid,$members) = getgrent() ){
   print "Name  = $name\n";
   print "Password  = $passwd\n";
   print "GID  = $gid\n";
   print "Members  = $members\n";
}


Copyright © tutorialspoint.com