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


Perl setgrent用法及代码示例



描述

此函数将枚举设置(或重置)到组条目集的开头。这个函数应该在第一次调用 getgrent 之前调用。

用法

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

setgrent

返回值

此函数不返回任何值。

示例

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

#!/usr/bin/perl -w

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

setgrent();    # Set the beginnging of the group database;

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

endpwent;  #claose the database;

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

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  = 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 setgrent Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。