描述
此函数迭代 /etc/group 文件中的条目。在列表上下文中返回以下内容 -
($name, $passwd, $gid, $members)
$members 标量包含作为组成员的登录名的空格分隔列表。仅在标量上下文中使用时才返回组名。在 Windows 下,考虑使用 Win32API::Net 模块。
用法
以下是此函数的简单语法 -
getgrent
返回值
此函数返回标量上下文和列表上下文中的组名称(名称、密码、组 ID 和成员列表。
示例
以下是显示其基本用法的示例代码 -
#!/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";
}
执行上述代码时,会产生以下结果 -
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 =
相关用法
- Perl getgrnam用法及代码示例
- Perl getgrgid用法及代码示例
- Perl getpwnam用法及代码示例
- Perl getservent用法及代码示例
- Perl getnetbyname用法及代码示例
- Perl getprotoent用法及代码示例
- Perl getnetent用法及代码示例
- Perl gethostent用法及代码示例
- Perl getsockopt用法及代码示例
- Perl getpeername用法及代码示例
- Perl getprotobynumber用法及代码示例
- Perl getservbyname用法及代码示例
- Perl getpwent用法及代码示例
- Perl gethostbyaddr用法及代码示例
- Perl getnetbyaddr用法及代码示例
注:本文由纯净天空筛选整理自 Perl getgrent Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。