当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Perl getgrgid用法及代码示例



描述

此函数按组 ID 查找组文件条目。在列表上下文中返回以下内容 -

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

$members 标量包含作为组成员的登录名的空格分隔列表。返回标量上下文中的组名。有关检索整个组文件的更有效方法,请参阅 getgrent。在 Windows 下,考虑使用 Win32API::Net 模块。

用法

以下是此函数的简单语法 -

getgrgid GID

返回值

此函数返回在标量上下文中它返回组名称和列表上下文(名称、密码、组 ID 和成员列表。

示例

以下是显示其基本用法的示例代码 -

#!/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";
}

执行上述代码时,会产生以下结果 -

Name  = root
Password  = x
GID  = 0
Members  = 
Name  = bin
Password  = x
GID  = 1
Members  = 
Name  = daemon
Password  = x
GID  = 2
Members  = 
Name  = sys
Password  = x
GID  = 3
Members  = 
Name  = adm
Password  = x
GID  = 4
Members  = 
Name  = tty
Password  = x
GID  = 5
Members  = 
Name  = disk
Password  = x
GID  = 6
Members  = 
Name  = lp
Password  = x
GID  = 7
Members  = 
.
.
.
.
Name  = apache
Password  = x
GID  = 48
Members  = 
Name  = rexx
Password  = x
GID  = 1001
Members  = 
Name  = objc
Password  = x
GID  = 1002
Members  = 

相关用法


注:本文由纯净天空筛选整理自 Perl getgrgid Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。