Perl getgrgid Function

Advertisements


Description

This function looks up the group file entry by group ID. 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 in a scalar context. For a more efficient method of retrieving the entire groups file, see getgrent. Under Windows, consider using the Win32API::Net module.

Syntax

Following is the simple syntax for this function:

getgrgid GID

Return Value

This function returns In scalr context it returns Group name and in list context (Name, Password, Group ID, and member list.

Example

Following is the example code showing its basic usage:

#!/usr/bin/perl

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

When above code is executed, it produced following result:

Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root
.
.
.
Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root
Name  = root
Password  = x
GID  = 0
Members  = root


Advertisements
Advertisements