Perl getgrent Function

Advertisements


Description

This function 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.

Syntax

Following is the simple syntax for this function:

getgrent

Return Value

This function returns Group name in scalr context 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() ){
   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  = bin
Password  = x
GID  = 1
Members  = root bin daemon
Name  = daemon
Password  = x
GID  = 2
Members  = root bin daemon
Name  = sys
Password  = x
GID  = 3
Members  = root bin adm
Name  = adm
Password  = x
GID  = 4
Members  = root adm daemon
Name  = tty
Password  = x
GID  = 5
Members  = 
.
.
.
Name  = fuse
Password  = x
GID  = 496
Members  = 
Name  = kvm
Password  = x
GID  = 36
Members  = qemu
Name  = qemu
Password  = x
GID  = 107
Members  = 
Name  = com
Password  = x
GID  = 501
Members  = 
Name  = webgrp
Password  = x
GID  = 502
Members  = com
Name  = railo
Password  = x
GID  = 495
Members  = 


Advertisements
Advertisements